SSLError证书验证失败的Python API
我得到以下错误:SSLError证书验证失败的Python API,python,api,python-requests,response,Python,Api,Python Requests,Response,我得到以下错误: context = ssl._create_unverified_context() urllib2.urlopen("https://no-valid-cert", context=context) 回溯(最近一次呼叫最后一次): 文件“C:\Python27\Scripts\Vehicle Model.py”,第10行,在 urllib2.urlopen(“https://no-valid-cert,context=context) 文件“C:\Python27\lib\
context = ssl._create_unverified_context()
urllib2.urlopen("https://no-valid-cert", context=context)
回溯(最近一次呼叫最后一次):
文件“C:\Python27\Scripts\Vehicle Model.py”,第10行,在
urllib2.urlopen(“https://no-valid-cert,context=context)
文件“C:\Python27\lib\urllib2.py”,第154行,在urlopen中
返回opener.open(url、数据、超时)
文件“C:\Python27\lib\urllib2.py”,第431行,打开
响应=自身打开(请求,数据)
文件“C:\Python27\lib\urllib2.py”,第449行,处于打开状态
"开放",
文件“C:\Python27\lib\urllib2.py”,第409行,在调用链中
结果=func(*args)
文件“C:\Python27\lib\urllib2.py”,第1240行,https\u open
上下文=自身(上下文)
文件“C:\Python27\lib\urllib2.py”,第1197行,在do\u open中
引发URL错误(err)
URL错误:
您应该首先用curl
验证所有设置是否正确。以下是我将使用的步骤:
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>
如果这两种方法都有效,那么请求也应该有效。如果希望在不验证SSL的情况下使用请求,可以使用参数get
curl --version
curl -v https://api.edmunds.com/
# this latter should verify that SSL and libcurl are working properly on the computer
尝试以下操作:当我添加行:context=ssl.\u create\u unverified\u context()urlib2.urlopen(“,context=context”)时,我会得到另一个错误:URLError:
curl --version
curl -v https://api.edmunds.com/
# this latter should verify that SSL and libcurl are working properly on the computer
session.get('https://api.edmunds.com/', verify=False)