title: Python Document Requests
body: <p>I requested a document from a web page using a socket and it returns error 400 Bad requests. what can i do? Here is the code;</p>
  
  <pre><code>import socket
  s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  
  s.connect(('www.py4e.org',80))
  
  cmd='GET https://www.py4e.org/lectures3/Pythonlearn-11-Regex-Handout.txt         HTTP/1.1\r\n\r\n'.encode()
  
  #headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:63.0)    Gecko/20100101 Firefox/63.0'}
  
  s.send(cmd)
  while True:
      data=s.recv(512)
      if len(data)&lt;1: break
  
  print(data.decode(),end='')
  
  s.close()
  </code></pre>
  
  <p>This is the output i got:</p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Date: Wed, 17 Oct 2018 20:50:29 GMT
  Server: Apache
  Content-Length: 226
  Connection: close
  Content-Type: text/html; charset=iso-8859-1
  
  &lt;!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"&gt;
  &lt;html&gt;&lt;head&gt;
  &lt;title&gt;400 Bad Request&lt;/title&gt;
  &lt;/head&gt;&lt;body&gt;
  &lt;h1&gt;Bad Request&lt;/h1&gt;
  &lt;p&gt;Your browser sent a request that this server could not understand.&lt;br    /&gt;
  &lt;/p&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>