简体   繁体   English

python foursquare - SSL3证书验证失败

[英]python foursquare - SSL3 certificate verify failed

I'm trying to make a userless request to the Foursquare API using Mike Lewis' Python wrapper - https://github.com/mLewisLogic/foursquare : 我正在尝试使用Mike Lewis的Python包装器向Foursquare API发出无用户请求 - https://github.com/mLewisLogic/foursquare

client = foursquare.Foursquare(client_id=Client_ID, client_secret=Client_Secret)
categs = client.venues.categories()

Intermittently , I get a "Error connecting to Foursquare API" msg. 间歇性地 ,我得到一个“错误连接到Foursquare API”的消息。 Running a logger to catch a more detailed message produces: 运行记录器以捕获更详细的消息会产生:

"SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed" “SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败”

This didn't use to happen and occurs both on my local Windows development machine and on a server running ubuntu. 在我的本地Windows开发机器和运行ubuntu的服务器上都没有发生这种情况。 Am I missing something basic here about security certificates? 我是否遗漏了一些关于安全证书的基本内容? The problem is intermittent and sometimes just leaving it a minute and retrying fixes the problem temporarily. 这个问题是间歇性的,有时候只需要一分钟就可以重试并暂时修复问题。

I've downloaded the latest 20120716 version of the wrapper although in the code for init.py it still says API_VERSION = '20120608'. 我已经下载了最新的20120716版本的包装器,尽管在init.py的代码中它仍然说API_VERSION ='20120608'。 I'm using Python 2.73 and have also signed up for the Foursquare API key, using the id and secret in the above code. 我正在使用Python 2.73并且还使用上面代码中的id和secret注册了Foursquare API密钥。 I listed the urls, using my local IP:8000 and tried using separate keys for the local and dev machines but this seems to make no difference. 我列出了网址,使用我的本地IP:8000并尝试使用单独的密钥用于本地和开发机器,但这似乎没有区别。

Help much appreciated. 非常感谢。 Thanks. 谢谢。

I encountered the exact same problem yesterday. 我昨天遇到了完全相同的问题。 I searched a lot and tried a lot, and seem the following strategy works for my case (I'm not 100% sure but it's not reporting the error any longer). 我搜索了很多并尝试了很多,似乎以下策略适用于我的情况(我不是100%肯定,但它不再报告错误)。

1) Download http://curl.haxx.se/ca/cacert.pem 1)下载http://curl.haxx.se/ca/cacert.pem

wget http://curl.haxx.se/ca/cacert.pem

2) Go to your Python httplib2 dir. 2)转到Python httplib2目录。 Mine is at /usr/local/lib/python2.7/dist-packages/httplib2 我的位于/usr/local/lib/python2.7/dist-packages/httplib2

cd /usr/local/lib/python2.7/dist-packages/httplib2

3) Back up the current certificate 3)备份当前证书

cp cacerts.txt backup_cacerts.txt

4) And then copy the downloaded file there and rename it as cacerts.txt 4)然后将下载的文件复制到那里并将其重命名为cacerts.txt

mv cacert.pem cacerts.txt

That's it. 而已。

Hope it helps. 希望能帮助到你。 If not recover from the backup file and try other methods. 如果没有从备份文件中恢复并尝试其他方法。

My foursquare scripts work all right after I change this : ) 我改变了这个后,我的foursquare脚本工作正常:)

Install or upgrade the certifi package: 安装或升级certifi包:

pip install --upgrade certifi

This is the solution recommended by urllib3 (which is used by many projects including requests , which in turn is used by the foursquare library linked above and many other libraries): http://urllib3.readthedocs.io/en/latest/user-guide.html#certificate-verification 这是urllib3推荐的解决方案(许多项目都使用它,包括requests ,而上面链接的foursquare库和许多其他库使用这些requests ): http//urllib3.readthedocs.io/en/latest/user- guide.html#证书验证

If you need to use this for a packages which doesn't use urllib3, but httplib2 for example, you copy the certifi/cacerts.pem file to the httplib2/cacerts.txt . 如果您需要将此用于不使用urllib3的软件包,而是使用httplib2,则将certifi/cacerts.pem文件复制到httplib2/cacerts.txt The directories to copy from/to can be found by doing: 可以通过执行以下操作找到要复制的目录:

python -c 'import httplib2; import os.path; print(os.path.dirname(httplib2.__file__))'

python -c 'import certifi; import os.path; print(os.path.dirname(certifi.__file__))' 

If you are just using urllib2 , then the httplib2/ directory is not used, but a system location. 如果您只是使用urllib2 ,则不使用httplib2/目录,而是使用系统位置。 You can check the files being loooked with the something like following: 您可以使用以下内容检查被删除的文件:

strace python -c "import urllib2; urllib2.urlopen(urllib2.Request('https://google.com/'))" 2>&1 | grep 'open' | grep 'cert'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM