小编Alv*_*rid的帖子

Gspread 从 Python 传递凭证而不是 JSON

我使用 Gspread 尝试将 JSON 文件(Google API 服务应用程序凭据)上的内容作为脚本上的 python 字典传递。无论我在哪里使用脚本,我都尽量不携带 json 文件。

当我尝试在以下行中传递字典而不是 json 文件时,出现以下错误:

credentials = ServiceAccountCredentials.from_json_keyfile_name(auth_gdrive(), scope)
Run Code Online (Sandbox Code Playgroud)

类型错误:预期的 str、bytes 或 os.PathLike 对象,未设置

### auth_gdrive() returns a dictionary like this:

def auth_gdrive():
    dic = {
        "type": "miauuuuuu",
        "pass": "miauuuu"
    }
Run Code Online (Sandbox Code Playgroud)

我不允许展示 dic 中的真实内容。

python gspread google-sheets-api

5
推荐指数
1
解决办法
7083
查看次数

将 Flash 消息类别添加到 @login_required 重定向

我正在使用 Python / Flask 构建一个 Web 应用程序。我正在使用 @login_required 装饰器保护视图。如果用户未登录,它将重定向到我的“登录”视图 URL,并添加一条 Flash 消息(“您需要登录才能查看此页面。”)。加载重定向视图(“登录”)后,会显示此闪现消息。由于该消息看起来来自@login_required,因此如何向该消息添加类别?

这是我的视图功能:

@app.route('/')
@app.route('/index')
# This is the decorator that redirects my request to the
# 'login' view, and adds a flash message. 
@login_required
#
def index():
    ...
    return render_template(...)
Run Code Online (Sandbox Code Playgroud)

为了将类别传递给即时消息,我可以“手动”添加,我可以执行以下操作。

flash_message = flash("User needs to be logged in to view this page", "category")
Run Code Online (Sandbox Code Playgroud)

python flask flask-login

2
推荐指数
1
解决办法
1834
查看次数

标签 统计

python ×2

flask ×1

flask-login ×1

google-sheets-api ×1

gspread ×1