try:
params = {
"appid": current_app.config['WX_APPID'],
"secret": current_app.config['WX_SECRET'],
"js_code": "122ww",
"grant_type": "authorization_code"
}
response = requests.get('https://api.weixin.qq.com/sns/jscode2session',params=params, verify=certifi.where())
logger.info("res:",response)
except Exception as e:
logger.error("捕获到异常:", {type(e).__name__})
logger.info(" 异常信息: ",{e})
{
- code:500
- msg:"WeChat API request failed: HTTPSConnectionPool(host='api.weixin.qq.com', port=443): Max retries exceeded with url: /sns/jscode2session?appid=wxd9d02a4ea82f8990&secret=cb8a943b55e08eed2537a22a107c472c&js_code=123&grant_type=authorization_code (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate (_ssl.c:1010)')))"
}
代码和调用错误如上。
本地调用正常,上了云托管就一直失败,尝试了,dockerfile 去安装证书还是不行
# 安装 curl 和 ca-certificates 来处理证书相关操作
RUN apt-get update && \
apt-get install -y curl ca-certificates && \
apt-get clean
# 下载根证书文件(以 Mozilla 的 CA 证书集合为例)
RUN curl -o /etc/ssl/certs/ca-certificates.crt https://curl.haxx.se/ca/cacert.pem