mardi 27 septembre 2016

HTTP/1.1 400 Bad Request. Bad number of command parts

Im trying to execute the following code from Chapter 12 of the book "Python for Informatics".

import socket
mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.py4inf.com', 80))
mysock.send('GET http://ift.tt/1sCbd7y HTTP/1.0\n\n')
while True:
    data = mysock.recv(512)
    if ( len(data) < 1 ) :
        break
    print data
mysock.close()

According to the book, the script should print the following:

HTTP/1.1 200 OK Date: Sun, 14 Mar 2010 23:52:41 GMT Server: Apache Last-Modified: Tue, 29 Dec 2009 01:31:22 GMT ETag: "143c1b33-a7-4b395bea" Accept-Ranges: bytes Content-Length: 167 Connection: close Content-Type: text/plain But soft what light through yonder window breaks It is the east and Juliet is the sun Arise fair sun and kill the envious moon Who is already sick and pale with grief

Unfortunately the variable data is filled with the following string:

'HTTP/1.1 400 Bad Request. Bad number of command parts ['GET', 'http://ift.tt/1sCbd7y', 'HTTP/1.0', 'X-WS-Ver:', '1.0']'

I cannot find any good explanation for this error. I hope someone can help!




Aucun commentaire:

Enregistrer un commentaire