如何将pickle文件存储到sqlalchemy数据库python中?

2024-04-23 22:53:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个python模块userbot来管理来自telegram的文件夹/文件https://github.com/adekmaulana/ProjectBish/blob/master/userbot/modules/google_drive.py,它在heroku上运行。
然而,在函数generate_credentials()中,在用户完成身份验证后,用户需要将其令牌放入heroku变量中,以便下次运行,这对用户来说有点不友好,因为一些用户不知道令牌字符串中的\n有多重要。
我想通过将凭证保存到pickle中(正如google api drive v3文档所说的那样),使其更方便用户,并将其存储到数据库中,但我一开始就迷路了。
我试图将解码的凭证放入字符串并保存到sqlalchemy数据库中,但当我加载它时,它会给我带来奇怪的错误,credentials认为它在云控制台google上运行???上面写着:
raise exceptions.DefaultCredentialsError(__HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
任何建议,使更多的用户友好将不胜感激,谢谢

更新:
所以问题是,在我调用build('drive','v3')之后,我从数据库中提取的凭据没有得到任何凭据


Tags: 模块字符串用户httpscom数据库herokugoogle
1条回答
网友
1楼 · 发布于 2024-04-23 22:53:55

通过使用credentials = Column(Text, nullable=False)修复此修复之前,我使用credentials = Column(String)
无论是String还是Text都是一样的,我都试过了,从数据库中拉出来后唯一的creds是空的,因为我以前没有使用nullable=False

相关问题 更多 >