Py请求,“未找到连接适配器”

时间:2018-06-29 11:24:46

标签: python python-3.x python-requests

  File "/usr/lib/python3/dist-packages/requests/api.py", line 67, in get
    return request('get', url, params=params, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 570, in send
    adapter = self.get_adapter(url=request.url)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 644, in get_adapter
    raise InvalidSchema("No connection adapters were found for '%s'" % url)
requests.exceptions.InvalidSchema: No connection adapters were found for '"https://framework.zend.com/manual/1.12/en/manual.html"'

URL有https,并且我已经从终端向该URL运行了一个请求,没有任何问题,因此我迷失了为什么它找不到适配器。我已经研究了源代码,并且在默认连接适配器下的https中肯定存在该源代码

self.adapters = OrderedDict()
self.mount('https://', HTTPAdapter())
self.mount('http://', HTTPAdapter())

感谢您的帮助

代码:

def fetchUrl(self, url):
    response = requests.get(url, params=self.PAYLOAD)

和有效载荷

PAYLOAD = {
        'timeout': 60,
        'headers': {
            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'
        }
    }

1 个答案:

答案 0 :(得分:2)

您的url参数中有多余的引号。

仔细查看错误消息中的URL字符串,它说(请注意引号)

requests.exceptions.InvalidSchema: No connection adapters were found for '"https://framework.zend.com/manual/1.12/en/manual.html"'

相反,它应该说

requests.exceptions.InvalidSchema: No connection adapters were found for 'https://framework.zend.com/manual/1.12/en/manual.html'