Python urllib2 exception nonnumeric port: 'port/' -


i wanted execute code found on python website:

    #!/usr/bin/python  import urllib2  f = urllib2.urlopen('http://www.python.org/') print f.read(100) 

but result this:

    traceback (most recent call last):   file "webserviceausführen.py", line 5, in <module>     f = urllib2.urlopen('http://www.python.org/')   file "/usr/lib/python2.7/urllib2.py", line 126, in urlopen     return _opener.open(url, data, timeout)   file "/usr/lib/python2.7/urllib2.py", line 400, in open     response = self._open(req, data)   file "/usr/lib/python2.7/urllib2.py", line 418, in _open     '_open', req)   file "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain     result = func(*args)   file "/usr/lib/python2.7/urllib2.py", line 1207, in http_open     return self.do_open(httplib.httpconnection, req)   file "/usr/lib/python2.7/urllib2.py", line 1146, in do_open     h = http_class(host, timeout=req.timeout) # parse host:port   file "/usr/lib/python2.7/httplib.py", line 693, in __init__     self._set_hostport(host, port)   file "/usr/lib/python2.7/httplib.py", line 721, in _set_hostport     raise invalidurl("nonnumeric port: '%s'" % host[i+1:]) httplib.invalidurl: nonnumeric port: 'port/' error in sys.excepthook: traceback (most recent call last):   file "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 70, in apport_excepthook     binary = os.path.realpath(os.path.join(os.getcwdu(), sys.argv[0]))   file "/usr/lib/python2.7/posixpath.py", line 71, in join     path += '/' + b unicodedecodeerror: 'ascii' codec can't decode byte 0xc3 in position 15: ordinal not in range(128)  original exception was: traceback (most recent call last):   file "webserviceausführen.py", line 5, in <module>     f = urllib2.urlopen('http://www.python.org/')   file "/usr/lib/python2.7/urllib2.py", line 126, in urlopen     return _opener.open(url, data, timeout)   file "/usr/lib/python2.7/urllib2.py", line 400, in open     response = self._open(req, data)   file "/usr/lib/python2.7/urllib2.py", line 418, in _open     '_open', req)   file "/usr/lib/python2.7/urllib2.py", line 378, in _call_chain     result = func(*args)   file "/usr/lib/python2.7/urllib2.py", line 1207, in http_open     return self.do_open(httplib.httpconnection, req)   file "/usr/lib/python2.7/urllib2.py", line 1146, in do_open     h = http_class(host, timeout=req.timeout) # parse host:port   file "/usr/lib/python2.7/httplib.py", line 693, in __init__     self._set_hostport(host, port)   file "/usr/lib/python2.7/httplib.py", line 721, in _set_hostport     raise invalidurl("nonnumeric port: '%s'" % host[i+1:]) httplib.invalidurl: nonnumeric port: 'port/' 

help pretty awesome because don't know how make such big error in such small program!

the exception thrown because have faulty proxy configuration.

on posix systems, library looks *_proxy environment variables (upper , lowercase). http url, that's http_proxy environment variable.

you can verify looking proxy variables:

import os  print {k: v k, v in os.environ.items() if k.lower().endswith('_proxy')} 

whatever value have configured on system not valid hostname , port combination , python choking on that.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -