Reputation: 27
I am try to get google sheet api authentication using pygsheets in the Replit. I saved the credentials json content into the "Secrets" function of Replit, the code is as below:
import pygsheets
import os
import json
creds = json.loads(os.environ.get('GDRIVE_API_CREDENTIALS'))
with open('gcreds.json', 'w') as fp:
json.dump(creds, fp)
gc = pygsheets.authorize(service_account_env_var = 'gcreds.json')
The 'GDRIVE_API_CREDENTIALS' is a below when i open the raw editor of Secrets:
"GDRIVE_API_CREDENTIALS": "{\"type\": \"service_account\", \"project_id\": \"xxx\", \"private_key_id\": \"xxx\", \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nxxx\\n-----END PRIVATE KEY-----\\n\", \"client_email\": \"xxx\", \"client_id\": \"xxx\", \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\", \"token_uri\": \"https://oauth2.googleapis.com/token\", \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\", \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/xxx.iam.gserviceaccount.com\"}"
After running the .py file it gives me a KeyError: 'gcreds.json'
Upvotes: 0
Views: 153