收藏
回答

flask部署云托管调微信ssl报错?

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


回答关注问题邀请回答
收藏

1 个回答

  • 北望沣渭
    北望沣渭
    发表于移动端
    03-02
    用http://,云拖管内部dns把域名绑定到内网环境了,要用https协议要在云拖管管理端开启一个开关,在容器重新部署的时候,他们才会把私有ssl证书添加到主机ca环境里
    03-02
    有用
    回复
登录 后发表内容