Traceback (most recent call last):
File "C:\Python27\Scripts\Vehicle Model.py", line 12, in <module>
response = requests.get(URL_PATTERN1)
File "C:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\api.py", line 69, in get
return request('get', url, params=params, **kwargs)
File "C:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\api.py", line 50, in request
response = session.request(method=method, url=url, **kwargs)
File "C:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\sessions.py", line 465, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\sessions.py", line 573, in send
r = adapter.send(request, **kwargs)
File "C:\Python27\lib\site-packages\requests-2.7.0-py2.7.egg\requests\adapters.py", line 431, in send
raise SSLError(e, request=request)
SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)
编译完代码后出现上述错误。我目前正在使用Edmunds API从其API中提取特定项目。当我在其他计算机上编译时,我不知道为什么我没有收到此错误消息。
然后当我添加:
context = ssl._create_unverified_context()
urllib2.urlopen("https://no-valid-cert", context=context)
我收到以下错误:
Traceback (most recent call last):
File "C:\Python27\Scripts\Vehicle Model.py", line 10, in <module>
urllib2.urlopen("https://no-valid-cert", context=context)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 431, in open
response = self._open(req, data)
File "C:\Python27\lib\urllib2.py", line 449, in _open
'_open', req)
File "C:\Python27\lib\urllib2.py", line 409, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 1240, in https_open
context=self._context)
File "C:\Python27\lib\urllib2.py", line 1197, in do_open
raise URLError(err)
URLError: <urlopen error [Errno 11004] getaddrinfo failed>
答案 0 :(得分:0)
您应首先使用curl
验证是否已正确设置所有内容。以下是我将使用的步骤:
curl --version
curl -v https://api.edmunds.com/
# this latter should verify that SSL and libcurl are working properly on the computer
如果这两个都有效,那么请求也应该有效。如果您想在不验证SSL的情况下使用请求,可以使用get
参数session.get('https://api.edmunds.com/', verify=False)
。
{{1}}