本文介绍了Python LocationValueError:未指定主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自上次Windows更新以来,我的python无法连接到Internet.

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'

只是我无法在Internet上点任何东西.

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.

推荐答案

错误位置:

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

如果 proxyEnable 是字符串,则会看到错误.原因是在您的注册表中,ProxyEnable设置为REG_SZ而不是REG_DWORD,因此进行更改就可以了.打开注册表:

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:

(您也可以直接搜索ProxyEnable)

(you can also directly search ProxyEnable)

删除ProxyEnable创建一个新的ProxyEnable表单(REG_SZ 0)(REG_DWORD 0x00000000(0))

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

请参见后面的图片,我的PC语言是中文,但是ProxyEnable的位置是相同的.

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

ProxyEnable的正确值

这篇关于Python LocationValueError:未指定主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 09:56