问题描述
我只是写了一个简单的python演示,却遇到了一个令人困惑的问题.
I just wrote a simple python demo,while met a confusing problem.
import requests
print(requests.get('http://www.sina.com.cn/'))
我知道正确的结果是返回Response [200].但是在我的WIN10 x64中,它返回以下错误,我想我的计算机可能会出现一些问题.
I know that right result is return Response [200].But in my WIN10 x64,it returns the following error,I guess maybe some problems occur in my computer.
Traceback (most recent call last):
File "C:\Users\CJY\Desktop\Python_Demo\web.py", line 2, in <module>
print(requests.get('http://www.sina.com.cn/'))
File "D:\python3.6.1\lib\site-packages\requests\api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "D:\python3.6.1\lib\site-packages\requests\api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "D:\python3.6.1\lib\site-packages\requests\sessions.py", line 518, in request
resp = self.send(prep, **send_kwargs)
File "D:\python3.6.1\lib\site-packages\requests\sessions.py", line 639, in send
r = adapter.send(request, **kwargs)
File "D:\python3.6.1\lib\site-packages\requests\adapters.py", line 403, in send
conn = self.get_connection(request.url, proxies)
File "D:\python3.6.1\lib\site-packages\requests\adapters.py", line 302, in get_connection
conn = proxy_manager.connection_from_url(url)
File "D:\python3.6.1\lib\site-packages\requests\packages\urllib3\poolmanager.py", line 279, in connection_from_url
pool_kwargs=pool_kwargs)
File "D:\python3.6.1\lib\site-packages\requests\packages\urllib3\poolmanager.py", line 408, in connection_from_host
self.proxy.host, self.proxy.port, self.proxy.scheme, pool_kwargs=pool_kwargs)
File "D:\python3.6.1\lib\site-packages\requests\packages\urllib3\poolmanager.py", line 218, in connection_from_host
raise LocationValueError("No host specified.")
requests.packages.urllib3.exceptions.LocationValueError: No host specified.
[Finished in 0.2s]
请帮助我!
推荐答案
错误位置:
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.
这篇关于Python错误:未指定主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!