Frage

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.

Traceback (most recent call last): r = requests.get("https://graph.facebook.com/cocacola") routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Thanks!

War es hilfreich?

Lösung

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. 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.

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"

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

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.

Andere Tipps

Have you installed certifi? A similar issue burned me recently too. Due to GPL licensing issues, Kenneth Reitz and co have had to move the SSL license bundle to another repo.

I just tried the following with the most up-to-date certifi from pypi installed and it seems to work fine:

>>> import requests
>>> r = requests.get("https://graph.facebook.com/cocacola") 
>>> r
<Response [200]>

More discussion about the licensing woes is available on this Github Issue thread (Full-discolure: I was the original poster of that thread).

If a new certifi doesn't fix it, you might want to try the Requests Github Issue page. They're a very responsive and friendly community!

Edit: If an up-to-date certifi doesn't fix it, I highly recommend the other poster's suggestion to try verify=False

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top