调用api_alipay_trade_query 报urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)>
xiaowuyongzhi opened this issue · 3 comments
xiaowuyongzhi commented
Describe the problem
我通过证书方式配置
app_private_key_string 使用的是app私钥
app_public_key_cert_string
alipay_public_key_cert_string
alipay_root_cert_string
这里获取三个证书
Environment
OS version: mac
Python version: 3.6
Alipay version: 2.1.0
To reproduce
Code snippets:
from alipay import DCAliPay
alipay_public_key_cert_string = """-----BEGIN CERTIFICATE-----
MIIDsjCCApqgAwIBAgIQICAGKN86hcO45mc3O9ZEiTANBgkqhkiG9w0BAQsFADCBgjELMAkGA1UE
BhMCQ04xFjAUBgNVBAoMDUFudCBGaW5hbmNpYWwxIDAeBgNVBAsMF0NlcnRpZmljYXRpb24gQXV0
aG9yaXR5MTkwNwYDVQQDDDBBbnQgRmluYW5jaWFsIENlcnRpZmljYXRpb24gQXV0aG9yaXR5IENs
YXNzIDIgUjEwHhcNMjAwNjI4MDczNTUzWhcNMjIwNjI4MDczNTUzWjCBkjELMAkGA1UEBhMCQ04x
LTArBgNVBAoMJOadreW3nuays+ixoee9kee7nOenkeaKgOaciemZkOWFrOWPuDEPMA0GA1UECwwG
QWxpcGF5MUMwQQYDVQQDDDrmlK/ku5jlrp0o5Lit5Zu9Kee9kee7nOaKgOacr+aciemZkOWFrOWP
uC0yMDg4NzIxNDQ5OTkyNDkwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsufsfc0s
AR2fzV4/CeLjDaMCY25ZDrQZP+xe05Oo4OfwHjF9OfJRc+zobjrv0797eOtxf4h0Qr2gtabZ8J0l
J1bnhm/GPU9+RI/FD/IrhGG7NcW7kBJkjBOqQncQbJTaR07AJaZGDhYf0mgxaqXt9YOcbE26aHjF
n5LbmDw6KOgRP9516c+3/Fn2+NzcfgZx5BNsSgDR8i0WslpcCZXzzTRCuuOqz7HfD6sh+0U9oPnU
z5ypQyN/7SEJVzd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+62O963COgBBtrW9VaokJqzcdnN7X3NjgNVrr
xg6Pfbof5QoOI2Nw7ECV64eUqBDBJcvJpsRkiB3Lf/Rg1XVOlh02cveEClzAG0WuNGvlEHVzp+PY
O8/4E3EziKPw55Se75gBN7YAycNAb/B/Zj6YNedHtKBLV6USSaYqPHQOna6Fm9Q06LN1ETgXDvce
BQoI4ljyDQ4=
-----END CERTIFICATE-----"""
appid = '2021001163628298'
client = DCAliPay(
appid=appid,
app_notify_url='',
app_private_key_string=app_private_key_string,
app_public_key_cert_string=app_public_key_cert_string,
alipay_public_key_cert_string=alipay_public_key_cert_string,
alipay_root_cert_string=alipay_root_cert_string
)
a = client.api_alipay_trade_query(out_trade_no="test20200101")
**Expected behavior **
我现在找不到请求失败原因
xiaowuyongzhi commented
我换了linux环境是ok的
xiaowuyongzhi commented
看样子像是macos环境问题
fzlee commented
https://stackoverflow.com/questions/42098126/mac-osx-python-ssl-sslerror-ssl-certificate-verify-failed-certificate-verify
看看这个东西, macos自带的python 貌似有些问题.
你可以写一个简单的urllib函数, 请求https://openapi.alipay.com 应该就会报错.