Python HTTP/1.1 400 Bad Request. Easy textbook example
<p>Do you know what is going on?</p>

<p>With this code...</p>

<pre><code> import socket

 mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 mysock.connect(('www.py4inf.com', 80))
 mysock.send('GET http://www.py4inf.com/code/romeo.txt HTTP/1.0\n\n')

 while True:
     data = mysock.recv(512)
     if ( len(data) &lt; 1 ) :
         break
     print data;

 mysock.close()
</code></pre>

<p>I get the correct answer:</p>

<pre><code> %run "c:\users\miguel~1\appdata\local\temp\tmp6uahvi.py"
 HTTP/1.1 200 OK
 Content-Type: text/plain
 Content-Length: 167
 Connection: close
 Date: Tue, 30 Aug 2016 14:20:52 GMT
 Server: Apache
 Last-Modified: Fri, 04 Dec 2015 19:05:04 GMT
 ETag: "a7-526172f5b5d89"
 Accept-Ranges: bytes
 Cache-Control: max-age=604800, public
 Access-Control-Allow-Origin: *
 Access-Control-Allow-Headers: origin, x-requested-with, content-type
 Access-Control-Allow-Methods: GET

 [... Some random text ...]
</code></pre>

<p>The exercise now says to modify the example to be able to connect to pythonlearn.com and read a text file. I don't understand why I get a Bad Request error now...</p>

<pre><code> import socket

 mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 mysock.connect(('www.pythonlearn.com', 80))
 mysock.send('GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n')

 while True:
     data = mysock.recv(512)
     if ( len(data) &lt; 1 ) :
         break
     print data;

 mysock.close()
</code></pre>

<p>I get a <strong>HTTP/1.1 400 Bad Request</strong></p>

<pre><code> HTTP/1.1 400 Bad Request
 Date: Tue, 30 Aug 2016 14:31:19 GMT
 Connection: close
 Set-Cookie: __cfduid=d8fbb6ce8ae7a7163f9bcdb6ffd3c7c681472567479; expires=Wed, 30-Aug-17 14:31:19 GMT; path=/; domain=.pythonlearn.com; HttpOnly
 Server: cloudflare-nginx
 CF-RAY: 2da8f21c332550fe-MIA
</code></pre>

<p>Why? Thanks!</p>