Python LocationValueError: No host specified

2019-05-18 22:43发布

My python can't connect to the Internet since last time my Windows updated.

When I pip something , error goes like

if host.startswith('['):
   AttributeError: 'NoneType' object has no attribute 'startswith'

It is just that I can't pip anything on the Internet, anything.

And then I thought maybe something went wrong with my system, so I tried checking if "requests" worked correctly. But hosts error goes like

  r = requests.get('http://www.baidu.com')
  Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Program Files (x86)\Anaconda3\lib\site-packages\requests\api.py", 
    line 70, in get
    return request('get', url, params=params, **kwargs)
  File "D:\Program Files (x86)\Anaconda3\lib\site-packages\requests\api.py", 
    line 56, in request
    return session.request(method=method, url=url, **kwargs)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\sessions.py", line 488, in request
    resp = self.send(prep, **send_kwargs)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\sessions.py", line 609, in send
    r = adapter.send(request, **kwargs)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\adapters.py", line 390, in send
    conn = self.get_connection(request.url, proxies)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\adapters.py", line 291, in get_connection
    conn = proxy_manager.connection_from_url(url)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\packages\urllib3\poolmanager.py", line 222, in 
    connection_from_url
    return self.connection_from_host(u.host, port=u.port, scheme=u.scheme)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\packages\urllib3\poolmanager.py", line 331, in 
    connection_from_host
    self.proxy.host, self.proxy.port, self.proxy.scheme)
  File "D:\Program Files (x86)\Anaconda3\lib\site-
    packages\requests\packages\urllib3\poolmanager.py", line 167, in 
    connection_from_host
    raise LocationValueError("No host specified.")
    requests.packages.urllib3.exceptions.LocationValueError: No host 
  specified.

I've used "requests" for hundreds of times before my computer went wrong. And I 've never seen errors like this before. By the way, my Internet is working perfectly, or else I can't ask a question from here.

I don't understand what is wrong with my computer or host file, I'd appreciate it if someone can help me out.

1条回答
The star\"
2楼-- · 2019-05-18 23:01

error location:

Lib\urllib\request.py:
proxyEnable = winreg.QueryValueEx(internetSettings, 'ProxyEnable')[0]

if proxyEnable is string , you'll see the error. The reason is in your registry, ProxyEnable is set as REG_SZ but not REG_DWORD, so change it and all is ok. open the registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings \ ProxyEnable

(you can also directly search ProxyEnable)

delete ProxyEnable create a new ProxyEnable form (REG_SZ 0) to (REG_DWORD 0x00000000(0))

see follow pictures,my pc language is chinese, but the location for ProxyEnable is the same.

create a new ProxyEnable

right value for ProxyEnable

查看更多
登录 后发表回答