一、 问题:网络调用提示错误

  • HTTP调用时提示提示

    {SSLError}HTTPSConnectionPool(host='api.gradio.app', port=443): Max retries exceeded with url: /v2/tunnel-request (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self-signed certificate in certificate chain (_ssl.c:1006)')))
    

二、 代码

经定位,发现底层如下代码报错

代码1

httpx.get("https://api.gradio.app/v2/tunnel-request", timeout=3)

代码2

requests.get("https://api.gradio.app/v2/tunnel-request", timeout=3)

三、 原因及解决方法

3.1 原因

  • 因为该网站访问的证书校验不通过,故失败。关闭证书校验即可。

3.2 解决方法

  • 解决方法:在请求时,增加verify=False字段。

    response = httpx.get("https://api.gradio.app/v2/tunnel-request", verify=False, timeout=3)
    requests.get("https://api.gradio.app/v2/tunnel-request", verify=False, timeout=3)
    
Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐