user1814277 user1814277 - 3 months ago 26
Python Question

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:

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. Running a logger to catch a more detailed message produces:

"SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed"

This didn't use to happen and occurs both on my local Windows development machine and on a server running 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'. 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. 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.

Help much appreciated. Thanks.

Answer

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

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

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

2) Go to your Python httplib2 dir. Mine is at /usr/local/lib/python2.7/dist-packages/httplib2

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

3) Back up the current certificate

cp cacerts.txt backup_cacerts.txt

4) And then copy the downloaded file there and rename it as 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 : )