Wolfram Alpha Python: SSL: CERTIFICATE_VERIFY_FAILED 错误
Wolfram Alpha Python: SSL: CERTIFICATE_VERIFY_FAILED error
我一直在尝试 运行 这个简单的代码片段来检查我在 Python 上安装的 Wolfram Alpha。
这是我一直在尝试的代码 运行:
import ssl
import wolframalpha
app_id = "*****************"
client = wolframalpha.Client(app_id)
my_input = input("Question: ")
res = client.query(my_input)
answer = next(res.results).text
print(answer)
这是我一直面临的错误
Traceback (most recent call last):
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 964, in send
self.connect()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1400, in connect
server_hostname=server_hostname)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 817, in __init__
self.do_handshake()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\MARIA\TEST_walpha.py", line 6, in <module>
res = client.query(my_input)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wolframalpha\__init__.py", line 53, in query
resp = urllib.request.urlopen(url)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)>
现在我咨询了thispost,但是没有明确的答案,导入SSL库也没有解决我的问题
您可以尝试通过执行以下操作来全局禁用证书验证:
ssl._create_default_https_context = ssl._create_unverified_context
我一直在尝试 运行 这个简单的代码片段来检查我在 Python 上安装的 Wolfram Alpha。
这是我一直在尝试的代码 运行:
import ssl
import wolframalpha
app_id = "*****************"
client = wolframalpha.Client(app_id)
my_input = input("Question: ")
res = client.query(my_input)
answer = next(res.results).text
print(answer)
这是我一直面临的错误
Traceback (most recent call last):
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1318, in do_open
encode_chunked=req.has_header('Transfer-encoding'))
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1239, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1285, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1234, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1026, in _send_output
self.send(msg)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 964, in send
self.connect()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1400, in connect
server_hostname=server_hostname)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 817, in __init__
self.do_handshake()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\MARIA\TEST_walpha.py", line 6, in <module>
res = client.query(my_input)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\site-packages\wolframalpha\__init__.py", line 53, in query
resp = urllib.request.urlopen(url)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 526, in open
response = self._open(req, data)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 544, in _open
'_open', req)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 504, in _call_chain
result = func(*args)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "C:\Users\MARIA\AppData\Local\Programs\Python\Python36-32\lib\urllib\request.py", line 1320, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:847)>
现在我咨询了thispost,但是没有明确的答案,导入SSL库也没有解决我的问题
您可以尝试通过执行以下操作来全局禁用证书验证:
ssl._create_default_https_context = ssl._create_unverified_context