A problem with urllib
Bryan Olson
fakeaddress at nowhere.org
Tue Jul 2 04:26:59 EDT 2002
Aki Niimura wrote:
> Peter, thank you for trying out.
> Any further suggestion?
I did some diagnosis, and the problem seems to be a Linksys bug. The
router insists on getting the entire request in a single read, rather
than reading until the end of the headers (and content if present). The
URL library must be sending one line at a time or something like that.
The code below runs through two cases: the first retrieves the resource
as it should, and the second triggers the router bug. In the second
case, the router returns an "HTTP/1.1 401 Authorization Required" error
response, even though we send exactly the same request as in the first
case.
The code below also has the same bug as the Linksys router: it does just
one recv() and assumes it has the entire message. That works in many
cases, including demo'ing the problem here, but is not correct.
--Bryan
import socket
import base64
for demo in ("good", "bad"):
request_line = "GET /Status.htm HTTP1/0\r\n"
auth_header = ("Authorization: Basic %s\r\n" %
base64.encodestring(":admin"))
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.1.1", 80))
if demo == "good":
s.send(request_line + auth_header + "\r\n")
else:
s.send(request_line)
s.send(auth_header + "\r\n")
s.shutdown(1)
print s.recv(99999)
s.close()
print "\n\n\n\n"
More information about the Python-list
mailing list