标签: boxsdk

“NoneType”对象没有属性“from_settings_file”(boxsdk.JWTAuth)

我正在尝试使用 django 使用boxsdk将文件上传到box.com,同时将应用程序部署到heroku。问题是我的代码在本地开发服务器上运行良好,但在heroku 上运行不佳。如果应用程序在本地运行,它也可以工作heroku local web

对于本地开发服务器,我可以导入 json 文件进行身份验证。对于heroku,由于它不接受conf 文件,因此我使用heroku:config 将文件存储为环境变量。

from boxsdk import JWTAuth, Client
from io import StringIO
import os
jsonpath = f'{STATIC_ROOT}/conf/box.json'
try:
    auth = JWTAuth.from_settings_file(jsonpath)
except:
    BOXCONF = os.environ.get('BOXCONF')    
    msg = f'The value of BOXCONF is {BOXCONF}'
    capture_message(msg)
    auth = JWTAuth.from_settings_file(StringIO.new(BOXCONF))
client = Client(auth)
service_account = client.user().get()
print('Service Account user ID is {0}'.format(service_account.id))
Run Code Online (Sandbox Code Playgroud)

我已经使用 Sentry 的 capture_message 测试了 BOXCONF 的设置,它显示以下内容:

The value of BOXCONF is {
"boxAppSettings": {
    "clientID": "abcd",
    "clientSecret": "abc",
    "appAuth": {
    "publicKeyID": …
Run Code Online (Sandbox Code Playgroud)

python django python-3.x box boxsdk

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

标签 统计

box ×1

boxsdk ×1

django ×1

python ×1

python-3.x ×1