urllib2.urlopen() crashes on Windows 2008 Server

Ulli Horlacher framstag at rus.uni-stuttgart.de
Thu Dec 3 11:32:09 EST 2015


I have a Python2 program which runs fine on Windows 7, but
crashes on Windows 2008 Server R2 64 bit:

downloading http://fex.belwue.de/download/7za.exe
Traceback (most recent call last):
  File "<string>", line 1992, in <module>
  File "<string>", line 180, in main
  File "<string>", line 329, in get_ID
  File "<string>", line 1627, in check_7z
  File "C:\Software\Python\lib\urllib2.py", line 154, in urlopen
  File "C:\Software\Python\lib\urllib2.py", line 431, in open
  File "C:\Software\Python\lib\urllib2.py", line 449, in _open
  File "C:\Software\Python\lib\urllib2.py", line 409, in _call_chain
  File "C:\Software\Python\lib\urllib2.py", line 1227, in http_open
  File "C:\Software\Python\lib\urllib2.py", line 1200, in do_open
  File "C:\Software\Python\lib\httplib.py", line 1132, in getresponse
  File "C:\Software\Python\lib\httplib.py", line 485, in begin
  File "C:\Software\Python\lib\mimetools.py", line 25, in __init__
  File "C:\Software\Python\lib\rfc822.py", line 108, in __init__
  File "C:\Software\Python\lib\httplib.py", line 319, in readheaders
  File "C:\Software\Python\lib\socket.py", line 480, in readline
error: [Errno 10054] Eine vorhandene Verbindung wurde vom Remotehost geschlossen

This is the function where the error happens:

if python2: import urllib2 as urllib
if python3: import urllib.request as urllib

def check_7z():
  global sz

  sz = path.join(fexhome,'7za.exe')
  szurl = "http://fex.belwue.de/download/7za.exe"

  if not path.exists(sz) or path.getsize(sz) < 9999:
    try:
      szo = open(sz,'wb')
    except (IOError,OSError) as e:
      die('cannot write %s - %s' % (sz,e.strerror))
    printf("\ndownloading %s\n",szurl)
    try:
      req = urllib.Request(szurl)
      req.add_header('User-Agent',useragent)
      u = urllib.urlopen(req) # line 1627 #
    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))
    if u.getcode() == 200:
      copy_file_obj(u,szo)
      szo.close()
    else:
      die('cannot get %s - server reply: %d' % (szurl,u.getcode()))


The curious thing is: the download was successful, the file 7za.exe is
there in the local directory!

-- 
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