推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
woostundy
V2EX  ›  Python

Python requests SSL: CERTIFICATE_VERIFY_FAILED 错误

  •  
  •   woostundy · Jan 13, 2017 · 4281 views
    This topic created in 3592 days ago, the information mentioned may be changed or developed.

    requests 调用 API 报错 requests SSL: CERTIFICATE_VERIFY_FAILED ,但可以确认 API 的证书没问题,用浏览器都可以正常访问。大家遇到过这个问题吗?

    环境: ubuntu 14.04
    virtualenv python 2.7.6 requests 2.12.4

    参考过 http://stackoverflow.com/questions/29134512/insecureplatformwarning-a-true-sslcontext-object-is-not-available-this-prevent 这个问题,但依然没能解决。

    20 replies  •  2017-01-14 07:47:59 +08:00
    TKKONE
    TKKONE
    PRO
    Jan 13, 2017
    1
    requests.packages.urllib3.disable_warnings()
    woostundy
    woostundy
    OP
    Jan 13, 2017
    2
    @tumbzzc 直接忽略就相当于不验证,不太合适吧。
    没有直接解决方案吗?
    woostundy
    woostundy
    OP
    Jan 13, 2017
    3
    实在没办法的话只能 verify=False 了
    linbiaye
    linbiaye
    Jan 13, 2017
    4
    自签的证书吧? curl 报错么?
    lslqtz
    lslqtz
    Jan 13, 2017
    5
    如果不是自签的证书,就手动指定全部根证书位置吧。
    lslqtz
    lslqtz
    Jan 13, 2017
    6
    @linbiaye win 下的 curl 表示各种网站都报错 xD 。
    woostundy
    woostundy
    OP
    Jan 13, 2017
    7
    @linbiaye 通配符, curl 正常
    woostundy
    woostundy
    OP
    Jan 13, 2017
    8
    @woostundy 买的 GlobalSIgn 的通配符证书
    woshifyz
    woshifyz
    Jan 13, 2017❤️1
    9
    因为 certifi 的问题,你换个版本就行了,或者删掉
    woostundy
    woostundy
    OP
    Jan 13, 2017
    10
    @woshifyz 多谢~
    woostundy
    woostundy
    OP
    Jan 13, 2017
    11
    @woshifyz 不过卸载了也不好使,最新版本和 2015.04.28 那个版本都不行
    woshifyz
    woshifyz
    Jan 13, 2017
    12
    @woostundy 那可能就需要你自己调试下了,我这边只有 centos6.5 , uninstall certifi 之后是可以访问 https 的
    ox180
    ox180
    Jan 13, 2017
    13
    用 Python3
    binux
    binux
    Jan 13, 2017
    14
    看看 ssl 的协议 requests 是否支持
    shiny
    shiny
    Jan 13, 2017
    15
    配置 API 的证书时候有没有忽略中间证书?
    saymoon
    saymoon
    Jan 13, 2017
    16
    apt-get upgrade 试试。
    latyas
    latyas
    Jan 14, 2017❤️1
    17
    升级到 2.7.10 +
    SlipStupig
    SlipStupig
    Jan 14, 2017
    18
    @woostundy VERIFY=False ,直接解决,验证不验证无所谓,有些证书是自签的或者过期了,你想请求内容直接放弃就行,除非你怕被劫持流量
    013231
    013231
    Jan 14, 2017 via iPhone
    19
    缺少中间证书可以导致此问题(浏览器中正常, requests 验证失败)。
    linbiaye
    linbiaye
    Jan 14, 2017
    20
    你这个信息太少了, requests SSL: CERTIFICATE_VERIFY_FAILED ,没有说为啥失败。 curl 可以,猜测是因为 python 没能正确找到 ca 证书,得把为啥失败了贴出来。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1924 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 49ms · UTC 09:13 · PVG 17:13 · LAX 01:13 · JFK 04:13
    ♥ Do have faith in what you're doing.