urllib2.urlopen() crashes on Windows 2008 Server

Ulli Horlacher framstag at rus.uni-stuttgart.de
Sun Dec 6 04:38:04 EST 2015


Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> >> Connection reset by peer.
> >> 
> >> An existing connection was forcibly closed by the remote host. 
> >
> >This is not true.
> >The server is under my control. Die client has terminated the connection
> >(or a router between).

> The odds are still good that something on the server is configured to
> not make a clean shutdown of TCP connections (a router should not be
> involved as the TCP connection is from client IP to server IP, regardless
> of intervening MAC Ethernet routing). The RST is coming from the server.

No.
The server does not reset the connection.
It is the router/firewall.
> >How can I trap this within the python program?
> >I see no exception.
>> It's a socket error
>> https://docs.python.org/2/library/socket.html
> """
>> exception socket.error

Ok, I have now:
 try:
 req = urllib.Request(szurl)
 req.add_header('User-Agent',useragent)
 u = urllib.urlopen(req)
 except urllib.URLError as e:
 die('cannot get %s - %s' % (szurl,e.reason))
 except urllib.HTTPError as e:
 die('cannot get %s - server reply: %d %s' % (szurl,e.code,e.reason))
 except (IOError,httplib.BadStatusLine,httplib.HTTPException):
 die('cannot get %s - connection reset by router or firewall' % szurl)
 except socket.error as msg:
 die('cannot get %s - %s' % (szurl,msg))
-- 
Ullrich Horlacher Server und Virtualisierung
Rechenzentrum IZUS/TIK E-Mail: horlacher at tik.uni-stuttgart.de
Universitaet Stuttgart Tel: ++49-711-68565868
Allmandring 30a Fax: ++49-711-682357
70550 Stuttgart (Germany) WWW: http://www.tik.uni-stuttgart.de/


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /