我有一个小型Python应用程序,它提供了一个GUI,可以使用PysimpleGUI更新Google工作表.

这个过程运行得很好,但我需要将JSON密钥文件"放在"EXE文件的旁边,以便它运行(JSON为访问Google工作表提供身份验证密钥).

如果没有,是否有其他方法可以让最终用户尽可能地简单明了?

这是代码的当前相关部分:

import gspread
import pandas as pd
from oauth2client.service_account import ServiceAccountCredentials
import PySimpleGUI as sg

# define the scope
scope = ['https://spreadsheets.google.com/feeds','https://www.googleapis.com/auth/drive']


# add credentials to the account
creds = ServiceAccountCredentials.from_json_keyfile_name('ABCDEFG.json', scope)

# authorize the clientsheet 
client = gspread.authorize(creds)

推荐答案

正如@RJ Adriaansen所提到的,您可以创建一个字典来存储json密钥文件中的详细信息.您还可以使用ServiceAccountCredentials.from_json_keyfile_dict,以便保留代码的 struct .见以下示例:

creds = ServiceAccountCredentials.from_json_keyfile_dict({
    'client_email': xxx,
    'private_key': xxx,
    'type': xxx,
    'client_id': xxx,
    'private_key_id': xxx
}, scope)

参考号:

样品:

Python相关问答推荐

如何从具有多个嵌入选项卡的网页中Web抓取td类元素

使用plotnine和Python构建地块

Python多处理:当我在一个巨大的pandas数据框架上启动许多进程时,程序就会陷入困境

为什么带有dropna=False的groupby会阻止后续的MultiIndex.dropna()工作?

如何使用html从excel中提取条件格式规则列表?

什么相当于pytorch中的numpy累积ufunc

按顺序合并2个词典列表

如何更改分组条形图中条形图的 colored颜色 ?

numpy卷积与有效

调用decorator返回原始函数的输出

计算天数

Pandas Data Wrangling/Dataframe Assignment

为什么if2/if3会提供两种不同的输出?

Geopandas未返回正确的缓冲区(单位:米)

未调用自定义JSON编码器

pysnmp—lextudio使用next()和getCmd()生成器导致TypeError:tuple对象不是迭代器''

Python 3试图访问在线程调用中实例化的类的对象

PYTHON中的selenium不会打开 chromium URL

如何在Python中画一个只能在对角线内裁剪的圆?

将时间序列附加到数据帧