urllib.open problem

Fredrik Lundh fredrik at pythonware.com
Thu Sep 15 10:45:36 CEST 2005

Astan Chee wrote:

>     I have a python script which runs perfectly on my machine.
>     However a machine that I tested it on gives the following error
> message:
>     Traceback (most recent call last):
>       File "whip.py", line 616, in OnRebootRunning
>       File "whip.py", line 626, in RebootCustom
>       File "urllib.pyc", line 77, in urlopen
>       File "urllib.pyc", line 170, in open
>     TypeError: cannot concatenate 'str' and 'NoneType' objects
>     The code snipplet where this error
>     happens is
>     f = urllib.urlopen("http://www.hotmail.com/)
>     notes= f.readlines()
> Does anyone know what causes this error? Im perplexed because it works
> on some machines and it doesnt work on other computers although they all
> have the same spec.

assuming you're using Python 2.4, the relevant portion of urllib.py
looks like this:

        urltype, url = splittype(fullurl)
        if not urltype:
            urltype = 'file'
        if urltype in self.proxies:
            proxy = self.proxies[urltype]
            urltype, proxyhost = splittype(proxy)
            host, selector = splithost(proxyhost)
            url = (host, fullurl) # Signal special case to open_*()
            proxy = None
        name = 'open_' + urltype # <-- this is line 170

the error message indicates that urltype is None when you get to
line 170, and the only way it can get set to None is a bogus proxy
setting (causing splittype to fail).

checking the environment for things that end with "_proxy" should


More information about the Python-list mailing list