Вопрос по python – Как исправить исключение httplib.BadStatusLine?

5
URL = "MY HTTP REQUEST URL"
XML = "<port>0</port>"

parameter = urllib.urlencode({'XML': XML})
response = urllib.urlopen(URL, parameter)
print response.read()


IOError: ('http protocol error', 0, 'got a bad status line', None)

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceededstackoverflow.com/q/10707959/1350899 mata

Ваш Ответ

1   ответ
5

from socket import socket

host = 'localhost'
port = 80
path = "/your/url"
xmlmessage = "<port>0</port>"

s = socket()
s.connect((host, port))
s.send("POST %s HTTP/1.1\r\n" % path)
s.send("Host: %s\r\n" % host)
s.send("Content-Type: text/xml\r\n")
s.send("Content-Length: %d\r\n\r\n" % len(xmlmessage))
s.send(xmlmessage)
for line in s.makefile():
    print line,
s.close()

HTTP/1.1 200 OK
<response headers>

<response body>

Похожие вопросы