V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2017-01-13 18:20:02 +08:00 · 3372 次点击
    这是一个创建于 2652 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2017-01-14 07:47:59 +08:00
    tumbzzc
        1
    tumbzzc  
       2017-01-13 18:28:53 +08:00
    requests.packages.urllib3.disable_warnings()
    woostundy
        2
    woostundy  
    OP
       2017-01-13 18:35:30 +08:00
    @tumbzzc 直接忽略就相当于不验证,不太合适吧。
    没有直接解决方案吗?
    woostundy
        3
    woostundy  
    OP
       2017-01-13 18:39:07 +08:00
    实在没办法的话只能 verify=False 了
    linbiaye
        4
    linbiaye  
       2017-01-13 18:46:02 +08:00
    自签的证书吧? curl 报错么?
    lslqtz
        5
    lslqtz  
       2017-01-13 18:46:33 +08:00
    如果不是自签的证书,就手动指定全部根证书位置吧。
    lslqtz
        6
    lslqtz  
       2017-01-13 18:46:59 +08:00
    @linbiaye win 下的 curl 表示各种网站都报错 xD 。
    woostundy
        7
    woostundy  
    OP
       2017-01-13 19:36:55 +08:00
    @linbiaye 通配符, curl 正常
    woostundy
        8
    woostundy  
    OP
       2017-01-13 19:37:44 +08:00
    @woostundy 买的 GlobalSIgn 的通配符证书
    woshifyz
        9
    woshifyz  
       2017-01-13 19:44:10 +08:00   ❤️ 1
    因为 certifi 的问题,你换个版本就行了,或者删掉
    woostundy
        10
    woostundy  
    OP
       2017-01-13 19:54:11 +08:00
    @woshifyz 多谢~
    woostundy
        11
    woostundy  
    OP
       2017-01-13 20:45:06 +08:00
    @woshifyz 不过卸载了也不好使,最新版本和 2015.04.28 那个版本都不行
    woshifyz
        12
    woshifyz  
       2017-01-13 22:42:25 +08:00
    @woostundy 那可能就需要你自己调试下了,我这边只有 centos6.5 , uninstall certifi 之后是可以访问 https 的
    ox180
        13
    ox180  
       2017-01-13 23:01:38 +08:00
    用 Python3
    binux
        14
    binux  
       2017-01-13 23:16:46 +08:00
    看看 ssl 的协议 requests 是否支持
    shiny
        15
    shiny  
       2017-01-13 23:25:53 +08:00
    配置 API 的证书时候有没有忽略中间证书?
    saymoon
        16
    saymoon  
       2017-01-13 23:27:29 +08:00
    apt-get upgrade 试试。
    latyas
        17
    latyas  
       2017-01-14 01:23:26 +08:00   ❤️ 1
    升级到 2.7.10 +
    SlipStupig
        18
    SlipStupig  
       2017-01-14 01:58:48 +08:00
    @woostundy VERIFY=False ,直接解决,验证不验证无所谓,有些证书是自签的或者过期了,你想请求内容直接放弃就行,除非你怕被劫持流量
    013231
        19
    013231  
       2017-01-14 05:21:43 +08:00 via iPhone
    缺少中间证书可以导致此问题(浏览器中正常, requests 验证失败)。
    linbiaye
        20
    linbiaye  
       2017-01-14 07:47:59 +08:00
    你这个信息太少了, requests SSL: CERTIFICATE_VERIFY_FAILED ,没有说为啥失败。 curl 可以,猜测是因为 python 没能正确找到 ca 证书,得把为啥失败了贴出来。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1341 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:40 · PVG 07:40 · LAX 16:40 · JFK 19:40
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.