使用 Python 请求将文件数据放入 Autodesk API

PUT file data to a Autodesk API with Python Requests

我正在按照 here but getting stopped by a 403 at Step 4. I have a token with data:write and data:create scopes as specified in the docs 描述的过程(以及其他需要这些范围工作的 API 方法),但我无法获得成功的响应,我认为这取决于我发送文件数据。我的代码如下所示:

url = '{}oss/v2/buckets/{}/objects/{}'.format(self.DOMAIN, bucket_id, object_name)
with open(file_path, 'rb') as f:
    file_content = f.read()
response = self.session.put(url, data=file_content, headers={
    'content-type': 'application/octet-stream'
}

授权令牌已包含在 session 的 headers 中。以下是上传过程的日志:

INFO Creating storage for README.md file in Test Project project, folder urn:adsk.wipprod:fs.folder:co.XXXXXXXXXXXXXXXX
INFO Storage success, start PUT file to https://developer.api.autodesk.com/oss/v2/buckets/:wip.dm.prod/objects/eb0e0379-9958-45b5-8bb0-5f4111b7a037.md
WARNING Upload failed, status 403: {"developerMessage":"ACM check failed, user or calling service does not have access to perform this operation","userMessage":"","errorCode":"AUTH-012","more info":"http://developer.api.autodesk.com/documentation/v1/errors/AUTH-012"}

过去,我们有一个带有 Python 的示例代码和 v1 端点。我今天迁移到 v2。它看起来运作良好。你能看看它是否能帮助你解决你遇到的问题吗? https://github.com/xiaodongliang/forge.workflow-python-sample