title: "did not receive a valid HTTP response" when receiving image from android studio using python Websockets
body: <p>I am trying to build a WebSockets client that receives an image sent from a mobile app that is built using (android studio) using the simple example provided by this <a href="https://websockets.readthedocs.io/en/stable/intro.html#basic-example" rel="nofollow noreferrer">documentation</a>.
  but when I replace the IP address and port number with the ones provided by the mobile app I get the following error:</p>
  <pre><code>C:\Users\LENOVO\Anaconda3\python.exe &quot;D:/SBME/4th year/1at term/Electronics/Task3/Wclient.py&quot;
  Traceback (most recent call last):
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\http.py&quot;, line 139, in read_response
      status_line = await read_line(stream)
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\http.py&quot;, line 219, in read_line
      raise EOFError(&quot;line without CRLF&quot;)
  EOFError: line without CRLF
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\client.py&quot;, line 101, in read_http_response
      status_code, reason, headers = await read_response(self.reader)
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\http.py&quot;, line 141, in read_response
      raise EOFError(&quot;connection closed while reading HTTP status line&quot;) from exc
  EOFError: connection closed while reading HTTP status line
  
  The above exception was the direct cause of the following exception:
  
  Traceback (most recent call last):
    File &quot;D:/SBME/4th year/1at term/Electronics/Task3/Wclient.py&quot;, line 250, in &lt;module&gt;
      asyncio.get_event_loop().run_until_complete(rcv_img())
    File &quot;C:\Users\LENOVO\Anaconda3\lib\asyncio\base_events.py&quot;, line 573, in run_until_complete
      return future.result()
    File &quot;D:/SBME/4th year/1at term/Electronics/Task3/Wclient.py&quot;, line 10, in rcv_img
      async with websockets.connect(uri) as websocket:
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\client.py&quot;, line 517, in __aenter__
      return await self
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\client.py&quot;, line 547, in __await_impl__
      extra_headers=protocol.extra_headers,
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\client.py&quot;, line 290, in handshake
      status_code, response_headers = await self.read_http_response()
    File &quot;C:\Users\LENOVO\Anaconda3\lib\site-packages\websockets\client.py&quot;, line 103, in read_http_response
      raise InvalidMessage(&quot;did not receive a valid HTTP response&quot;) from exc
  websockets.exceptions.InvalidMessage: did not receive a valid HTTP response
  </code></pre>
  <p>I searched what is causing this error but unfortunately, I can not find the answer on the internet nor the documentation.</p>
  <p>here is the simple python code</p>
  <pre><code>import asyncio
  import websockets
  
  async def rcv_img():
      uri = &quot;ws://192.168.1.8:8080&quot;
      async with websockets.connect(uri) as websocket:
         
          img_rcv = await websocket.recv()
          # some image processing code here
  
  asyncio.get_event_loop().run_until_complete(rcv_img())
  </code></pre>
  <p>and the sending part in the mobile app</p>
  <pre><code>public class FileTxThread extends Thread {
          Socket socket;
  
          FileTxThread(Socket socket){
              this.socket= socket;
          }
  
          //@RequiresApi(api = Build.VERSION_CODES.O)
          @Override
          public void run() {
             File file  = new File(Environment.getExternalStorageDirectory(), &quot;Frame.jpg&quot;);
             WriteByteArray.toFile(imagebyte,file);
  
              byte[] bytes = new byte[(int) file.length()];
              BufferedInputStream bis;
              try {
                  bis = new BufferedInputStream(new FileInputStream(file));
                  bis.read(bytes, 0,bytes.length);
  
                  ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
                  oos.writeObject(bytes);
                  oos.flush();
                  socket.close();
                  final String sentMsg = &quot;File sent to: &quot; + socket.getInetAddress();
                  
                  MainActivity.this.runOnUiThread(new Runnable() {
  
                      @Override
                      public void run() {
                          Toast.makeText(MainActivity.this,
                                  sentMsg,
                                  Toast.LENGTH_LONG).show();
                      }});
  
              } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              } finally {
                  try {
                      socket.close();
                  } catch (IOException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
  
          }
      }
  
  </code></pre>