调用api_alipay_trade_cancel时报错
Closed this issue · 4 comments
Describe the bug
调用api_alipay_trade_cancel时报错,urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>
其是在raw_string = urlopen(url, timeout=15).read().decode("utf-8")处引起的。
Environment
Python version: Python 3.6.8
Alipay version:1.10.1
**Expected behavior **
File "/Users/charles/Projects/Infimind/ecpro-billing/app/trade/payments.py", line 107, in cancel
cancel_data = alipay.api_alipay_trade_cancel(**kwargs)
File "/Users/charles/Projects/Infimind/ecpro-billing/venv/lib/python3.6/site-packages/alipay/init.py", line 407, in api_alipay_trade_cancel
raw_string = urlopen(url, timeout=15).read().decode("utf-8")
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
return opener.open(url, data, timeout)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 526, in open
response = self._open(req, data)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 544, in _open
'_open', req)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
result = func(*args)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/urllib/request.py", line 1361, in https_open
context=self._context, check_hostname=self._check_hostname)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/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:852)>
你这边调用其他接口也应该报同样的错吧,看看是不是自己电脑启用了代理导致的
调用其他接口是正常的。以下是我目前的解决方案
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
cancel_data = alipay.api_alipay_trade_cancel(**kwargs)
这样关闭了可以使用。
看着像是证书验证不通过,导致请求失败
是的,使用上面那种方法全局关闭了ssl验证。这个问题解决了。应该是mac os特有的问题。通过在终端运行下面两条命令解决了。谢谢你帮我看这个问题~
pip install certifi
/Applications/Python\ 3.6/Install\ Certificates.command