Python: Socket send returns malformed URL
<p>Hello I am trying to access a file via python socket module and I am getting HTTP 400 Bad request error but I am not sure what mistake I have done. </p>

<pre><code>import socket
mysocket=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysocket.connect(('www.pythonlearn.com',80))
mysocket.send(b'GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n')
while True:
 data=mysocket.recv(512)
 if( len(data) &lt; 1 ):
  break
 print(data)
mysocket.close()
</code></pre>

<p>Error: </p>

<pre><code>=== RESTART: E:\My Data\coursera\Using_Python_to_Access_Web_Data\week3.py ===
b'HTTP/1.1 400 Bad Request\r\nDate: Wed, 21 Sep 2016 09:27:20 GMT\r\nConnection: close\r\nSet-Cookie: __cfduid=d0586f04e861e59d45b703f20ea77a17c1474450040; expires=Thu, 21-Sep-17 09:27:20 GMT; path=/; domain=.pythonlearn.com; HttpOnly\r\nServer: cloudflare-nginx\r\nCF-RAY: 2e5c7b12d01d5426-LAX\r\n\r\n'
&gt;&gt;&gt; 
</code></pre>

<p>I am out of ideas here , any help greatly appreciated.</p>

<p>Thank you.</p>

<p>The error is on the http request, Host and requested file should be separated.</p>

<pre><code>http_request  = 'GET /code/intro-short.txt HTTP/1.0\n'
http_request += 'Host:www.pythonlearn.com\n'
http_request += '\n'
mysocket.send(http_request)
</code></pre>

python sockets