如何使用外部托管的json授权pygsheets?

时间:2018-11-18 17:28:59

标签: pygsheets

gc = pygsheets.authorize(service_file='https://api.myjson.com/bins/******')

我现在尝试了此操作,但出现此错误:

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

我该怎么做?

1 个答案:

答案 0 :(得分:0)

Currenlty pygsheets希望service_file是一个文件。因此,您需要先下载远程文件,然后在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')