本文介绍了使用python请求模块的Facebook图形GET请求-证书验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个简短的python脚本,很有趣,可以检查几页的喜欢程度.我正在使用python请求模块.如下所示,出现了问题,有关证书.我对涉及网络的编程非常陌生,所以对我来说应该做什么并不明显. r = requests.get("http://www.google.com/")正确返回了一些内容.

I am writing a short python script for fun to check a few pages for the amount of likes. I am using the python requests module. As seen below, there was a problem, something about certificates. I am fairly new to programming involving the web, so it's not obvious to me what I should do. r = requests.get("http://www.google.com/") correctly returned something.

谢谢!

推荐答案

该错误似乎来自OpenSSL.您的环境中可能进行了一些配置,导致请求"将证书位置设置为不包含所需证书的位置.

That error looks like it is coming from OpenSSL. You might have some configuration in your environment that is causing Requests to set the certificate location to something that doesn't contain the certificate you need.

尝试调查请求"检查证书的可能方式:

Try investigating the possible ways that Requests might be checking for certificates:

  1. 它使用REQUESTS_CA_BUNDLE环境变量寻找配置.
  2. 它使用CURL_CA_BUNDLE环境变量检查卷曲兼容性.
  3. 如果可以导入certifi软件包,它将尝试导入证书列表.
  1. It look for configuration using REQUESTS_CA_BUNDLE environment variable.
  2. It checks for curl compatiblity check using CURL_CA_BUNDLE environment variable.
  3. It tries to import the certifi list if the certifi package can be imported.

检查您的环境中是否是REQUESTS_CA_BUNDLECURL_CA_BUNDLE之一:

Check to see if one of REQUESTS_CA_BUNDLE or CURL_CA_BUNDLE are in your environment:

env | egrep "REQUESTS_CA_BUNDLE|CURL_CA_BUNDLE"

如果设置了其中之一,则在验证证书时,请求可能正在使用该配置.如果不是,那么请求可能使用certifi.在这种情况下,也许值得对其进行更新:

If one of those are set, Requests is probably using that configuration when verifying certificates. If not then Requests is probably using certifi. In that case maybe it's worth updating it:

pip install -U certifi

如果失败,请尝试将verify=False传递给requests.get以使其跳过验证步骤.我建议您解决真正的问题,而不是仅仅将其关闭,但这可能有助于您深入浅出.

Failing that, try passing verify=False to requests.get to have it skip the verification step. I would recommend solving the real problem instead of just switching it off, but that might help you get to the bottom of it.

这篇关于使用python请求模块的Facebook图形GET请求-证书验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 07:45