Search code examples
python-2.7google-sheetsssl-certificateverifygspread

SSLHandshakeError certificate verify failed


I am trying to write to a spreadsheet from my windows desktop, using gspread and python. The following code works on my mac laptop, but when run on the pc, I get a SSLHandshakeError. I have made sure that the necessary file is available to the program, and have tried creating new projects with no luck, I always get the same error.

Here is the code:

#databaseTest.py
import sys
import os
import pyodbc
import json, gspread
from oauth2client.client import SignedJwtAssertionCredentials

json_key = json.load(open('H:\MyProject-ee653db0fe92.json'))
scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope)
print "Authorizing..."
try:
    gc = gspread.authorize(credentials)
    input("Done")
except:
    print "SSL error"
    input("Something went wrong")
    gspread.authorize(credentials)

And here is the last part of the error I get:

File "C:\Python27\lib\site-packages\httplib2\__init__.py", line 1059, in connect
raise SSLHandshakeError(e)
httplib2.SSLHandshakeError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

Solution

  • It turns out that the problem with connecting to the spreadsheet from the desktop was caused by the network it was connected to. The laptop was connected to a different network, which allowed it to communicate with the spreadsheet, but the desktop's network had a number of firewalls and security measures that prevented this.