我正在尝试使用 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)