urllib2.urlopen error "socket.error: [Errno 104] Connection reset by peer"

dieter dieter at handshake.de
Wed May 13 01:55:23 EDT 2015


"Jia CHEN" <jia.j.chen at foxmail.com> writes:

> I have the error below when trying to download the html content of a webpage. I can open this webpage in a browser without any problem.

"Connection reset by peer" means that the other side (the HTTP server
in your case) has closed the connection.

It may have looked at the "User-Agent" request header to differentiate
between a browser request and an automated (script) request.

To work around this, you may provide a "User-Agent" header
to your "urllib2.Request" (see the documentation) letting
the "User-Agent" to look as if the request had been done by a browser
("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
indicates a firefoy).




More information about the Python-list mailing list