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