OpenSSL.crypto.Error: [] in SignedJwtAssertionCredentials attempt
OpenSSL.crypto.Error: [] in SignedJwtAssertionCredentials attempt
我正在尝试使用 SignedJwtAssertionCredentials 登录以获取 gspread to work. I've followed the directions here 以及 python3 的注释。这是我的 class:
import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
class GoogleSpreadsheet():
def fetch(self):
gc = gspread.authorize(self.credentials)
wks = gc.open("TEST of Sheet (Responses)").sheet1
print(wks)
def __init__(self, client_email,pk):
scope = ['https://spreadsheets.google.com/feeds']
self.credentials = SignedJwtAssertionCredentials(client_email, bytes(pk, 'utf-8'), scope)
client_email
和 pk
从环境变量传递:
gs = GoogleSpreadsheet(app.config.get('GOOGLE_SPREADSHEET_CLIENT_EMAIL'), app.config.get('GOOGLE_SPREADSHEET_PK'))
环境变量是从googleauthjson文件中复制的:
export GOOGLE_SPREADSHEET_PK="-----BEGIN PRIVATE KEY-----\n...\n...keystuff...\n...\n-----END PRIVATE KEY-----\n"
每次尝试 OpenSSL.crypto.Error: []
都会出错
此处 的建议没有帮助,因为我的密钥未加密。
有什么建议吗?
在此线程的帮助下:https://github.com/google/oauth2client/issues/193
和一些摆弄,看起来你需要把私钥中的 \n
变成真正的换行符,如果你没有加载配置文件虽然 JSON.load
(gsheets 教程做的。)
我正在尝试使用 SignedJwtAssertionCredentials 登录以获取 gspread to work. I've followed the directions here 以及 python3 的注释。这是我的 class:
import json
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
class GoogleSpreadsheet():
def fetch(self):
gc = gspread.authorize(self.credentials)
wks = gc.open("TEST of Sheet (Responses)").sheet1
print(wks)
def __init__(self, client_email,pk):
scope = ['https://spreadsheets.google.com/feeds']
self.credentials = SignedJwtAssertionCredentials(client_email, bytes(pk, 'utf-8'), scope)
client_email
和 pk
从环境变量传递:
gs = GoogleSpreadsheet(app.config.get('GOOGLE_SPREADSHEET_CLIENT_EMAIL'), app.config.get('GOOGLE_SPREADSHEET_PK'))
环境变量是从googleauthjson文件中复制的:
export GOOGLE_SPREADSHEET_PK="-----BEGIN PRIVATE KEY-----\n...\n...keystuff...\n...\n-----END PRIVATE KEY-----\n"
每次尝试 OpenSSL.crypto.Error: []
此处
有什么建议吗?
在此线程的帮助下:https://github.com/google/oauth2client/issues/193
和一些摆弄,看起来你需要把私钥中的 \n
变成真正的换行符,如果你没有加载配置文件虽然 JSON.load
(gsheets 教程做的。)