How do I authorize pygsheets with an externally hosted json?

166 views Asked by At
gc = pygsheets.authorize(service_file='https://api.myjson.com/bins/******')

I tried this now, but I'm getting this error:

FileNotFoundError: [Errno 2] No such file or directory: 'https://api.myjson.com/bins/******'

How can I do this?

1

There are 1 answers

0
Nithin On

Currenlty pygsheets expects the service_file to be a file. So You will need to first download the remote file and then use it in pygsheets.

import requests 
import pygsheets
image_url = "https://api.myjson.com/bins/******"
r = requests.get(image_url)
with open("service.json",'wb') as f: 
    f.write(r.content)

gc = pygsheets.authorize(service_file='service.json')