[英]Box Python SDK - Getting access_denied_insufficient_permissions while trying to create a webhook
[英]Box Access denied - insufficient permission 403 Python JWT sdk
我正在嘗試使用 Python 將文件上傳到 Box。 我已按照以下步驟操作:
from boxsdk import JWTAuth
from boxsdk import Client
# read json configuration file
auth = JWTAuth.from_settings_file('config.json')
access_token = auth.authenticate_instance()
# initialize sdk client
client = Client(auth)
service_account = client.user().get()
print('Service Account user ID is {0}'.format(service_account.id))
#file name and path
file_name = 'FILE_NAME'
stream = open('PATH_TO_FILE', 'rb')
#box parameters
folder_id = '0'
user_id = '0'
user = client.user(user_id)
#make the call
box_file = client.as_user(user).folder(folder_id).upload_stream(stream, file_name)
print('File "{0}" uploaded to Box with file ID {1}'.format(box_file.name, box_file.id))
但在倒數第二行,它拋出了這個錯誤:
BoxAPIException: Message: Access denied - insufficient permission
Status: 403
Code: access_denied_insufficient_permissions
Request ID: vbqcplgq1cbpg5cj
Headers: {'Date': 'Thu, 29 Apr 2021 21:53:18 GMT', 'Content-Type': 'application/json; charset=UTF-8', 'Content-Length': '217', 'Connection': 'keep-alive', 'X-Envoy-Upstream-Service-Time': '100', 'Strict-Transport-Security': 'max-age=31536000', 'Cache-Control': 'no-cache, no-store'}
URL: https://upload.box.com/api/2.0/files/content
Method: POST
Context Info: None
我也嘗試了upload
而不是upload_stream
並得到了相同的結果。 有誰知道為什么我可能仍然沒有足夠的權限?
我認為您的問題在於:
user_id = '0'
user = client.user(user_id)
user_id
應該是有權訪問 Box 中文件夾的應用用戶帳戶的 ID。
https://developer.box.com/reference/post-users/
要創建帳戶,我通常使用 postman。
curl --location --request POST 'https://api.box.com/2.0/users' \
--header 'Authorization: Bearer {Your App Dev Token}' \
--header 'Content-Type: application/json' \
--data-raw '{"name": "{Name for New User}", "is_platform_access_only": true}'
響應將返回有關您剛剛創建的用戶的一些信息,其中一部分是 ID。
{
"id": 11446498,
...
"name": "{Name for New User}",
...
}
將此新用戶添加到您要上傳到的文件夾中,並將 ID 用作as_user
ID
在您的代碼示例中。 將 user_id 更新為返回的 ID。
user_id = '11446498'
user = client.user(user_id)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.