Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python请求模块时发生LocationValueError_Python_Python 3.x_Python Requests - Fatal编程技术网

使用python请求模块时发生LocationValueError

使用python请求模块时发生LocationValueError,python,python-3.x,python-requests,Python,Python 3.x,Python Requests,我一直在使用requests包与web交互,过去没有任何问题。最近,在使用一个大约一周没有使用的脚本时,我在执行例程requests.get()调用时遇到以下错误: LocationValueError: No host specified. 背景研究 在大量搜索python请求LocationValueError的各种排列之后,python请求没有主机错误和python urlib3 LocationValueError(根据堆栈跟踪,错误由请求下面使用的urlib3引发)我只在urllib

我一直在使用requests包与web交互,过去没有任何问题。最近,在使用一个大约一周没有使用的脚本时,我在执行例程
requests.get()
调用时遇到以下错误:

LocationValueError: No host specified.
背景研究 在大量搜索
python请求LocationValueError
的各种排列之后,
python请求没有主机错误
python urlib3 LocationValueError
(根据堆栈跟踪,错误由请求下面使用的
urlib3
引发)我只在
urllib3
文档中找到了这些信息:

异常urllib3.exceptions.LocationValueError

当给定URL输入出现问题时引发

我试过的 我认为我的requests包版本可能有问题,因为这可能是requests包中使用的最基本的调用之一,我做了以下操作:

  • 重新安装的请求
  • 使用pip创建虚拟环境并安装请求
  • 来自源的已安装请求
  • 专门安装urllib3
  • 从源代码处安装了python3.4,然后进行了尝试(目前我使用python3.5)
在所有情况下,我都使用以下代码查看请求是否仍抛出LocationValueError:

import requests
address = 'http://www.google.com/'    
requests.get(address)
这在过去一直有效。我在另一台电脑(一台ubuntu笔记本电脑)上进行了检查,它在那里工作,这让我觉得这个问题与我的电脑有关

问题的堆栈跟踪 下面是我在使用安装在virtualenv和python3.4中的请求时得到的堆栈跟踪

In [5]: import requests In [6]: requests.get('http://www.google.com/') --------------------------------------------------------------------------- LocationValueError Traceback (most recent call last) in () ----> 1 requests.get('http://www.google.com/') /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/api.py in get(url, params, **kwargs) 67 68 kwargs.setdefault('allow_redirects', True) ---> 69 return request('get', url, params=params, **kwargs) 70 71 /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/api.py in request(method, url, **kwargs) 48 49 session = sessions.Session() ---> 50 response = session.request(method=method, url=url, **kwargs) 51 # By explicitly closing the session, we avoid leaving sockets open which 52 # can trigger a ResourceWarning in some cases, and look like a memory leak /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 466 } 467 send_kwargs.update(settings) --> 468 resp = self.send(prep, **send_kwargs) 469 470 return resp /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/sessions.py in send(self, request, **kwargs) 574 575 # Send the request --> 576 r = adapter.send(request, **kwargs) 577 578 # Total elapsed time of the request (approximately) /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies) 335 """ 336 --> 337 conn = self.get_connection(request.url, proxies) 338 339 self.cert_verify(conn, request.url, verify, cert) /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/adapters.py in get_connection(self, url, proxies) 247 proxy = prepend_scheme_if_needed(proxy, 'http') 248 proxy_manager = self.proxy_manager_for(proxy) --> 249 conn = proxy_manager.connection_from_url(url) 250 else: 251 # Only scheme should be lower case /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/packages/urllib3/poolmanager.py in connection_from_url(self, url) 137 """ 138 u = parse_url(url) --> 139 return self.connection_from_host(u.host, port=u.port, scheme=u.scheme) 140 141 def urlopen(self, method, url, redirect=True, **kw): /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/packages/urllib3/poolmanager.py in connection_from_host(self, host, port, scheme) 246 247 return super(ProxyManager, self).connection_from_host( --> 248 self.proxy.host, self.proxy.port, self.proxy.scheme) 249 250 def _set_proxy_headers(self, url, headers=None): /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/packages/urllib3/poolmanager.py in connection_from_host(self, host, port, scheme) 108 109 if not host: --> 110 raise LocationValueError("No host specified.") 111 112 scheme = scheme or 'http' LocationValueError: No host specified. 在[5]中:导入请求 在[6]中:requests.get('http://www.google.com/') --------------------------------------------------------------------------- LocationValueError回溯(最近一次调用上次) 在() ---->1.获取请求http://www.google.com/') /get中的home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/api.py(url,参数,**kwargs) 67 68 kwargs.setdefault('allow_redirects',True) --->69返回请求('get',url,params=params,**kwargs) 70 71 /请求中的home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/api.py(方法、url、**kwargs) 48 49 session=sessions.session() --->50响应=session.request(方法=method,url=url,**kwargs) 51#通过显式关闭会话,我们可以避免让套接字保持打开状态 52#在某些情况下会触发资源警告,看起来像内存泄漏 /请求中的home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/sessions.py(self、方法、url、参数、数据、标题、cookie、文件、身份验证、超时、允许重定向、代理、挂钩、流、验证、证书、json) 466 } 467发送文件更新(设置) -->468 resp=自我发送(准备,**发送) 469 470返回响应 /发送中的home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/sessions.py(self,request,**kwargs) 574 575#发送请求 -->576 r=适配器.send(请求,**kwargs) 577 578#请求的总运行时间(大约) /发送中的home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/adapters.py(self、request、stream、timeout、verify、cert、proxies) 335 """ 336 -->337 conn=self.get\u连接(request.url,代理) 338 339自我验证(conn,request.url,verify,cert) /get_连接中的home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/adapters.py(self、url、代理) 247 proxy=prepend\u scheme\u(如果需要)(代理,“http”) 248 proxy_manager=self.proxy_manager(代理) -->249 conn=proxy\u manager.connection\u from\u url(url) 250其他: 251#仅方案应为小写 /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/packages/urllib3/poolmanager.py在连接中从_url(self,url) 137 """ 138 u=解析url(url) -->139从主机返回自连接(u.host,port=u.port,scheme=u.scheme) 140 141 def urlopen(self,method,url,redirect=True,**kw): /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/packages/urllib3/poolmanager.py从主机(自身、主机、端口、方案)连接 246 247从主机返回超级(ProxyManager,自)。连接( -->248 self.proxy.host、self.proxy.port、self.proxy.scheme) 249 250个def\u set\u proxy\u标题(self、url、headers=None): /home/michael/Documents/my_test_env/lib/python3.4/site-packages/requests/packages/urllib3/poolmanager.py从主机(自身、主机、端口、方案)连接 108 109如果不是主机: -->110 raise LOCATIONVALUEVERROR(“未指定主机”) 111 112方案=方案或“http” LocationValueError:未指定主机。
如果有人能帮我解释错误的原因或给我指出正确的方向,我将不胜感激。当我使用request.Session对象获取扩展会话的页面时,也会发生此问题。

对于我来说,问题是请求的url重定向到了位置:https/,该位置可能无效,但urllib3无法处理。

您有任何本地dns配置吗?像定制
主机
之类的?代理防火墙?我过去使用过VPN,但即使它被停用,我仍然会收到错误。除此之外,自从我安装操作系统以来,我还没有更改网络配置。你能用
urllib
打个电话吗?Asin,这是否特定于
请求
模块?您使用的是哪种操作系统?