使用 Python 请求将文件数据放入 Autodesk API [英] PUT file data to a Autodesk API with Python Requests

查看:17
本文介绍了使用 Python 请求将文件数据放入 Autodesk API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遵循此处 但在第 4 步被 403 阻止.我有一个 data:writedata:create 范围为 在文档中指定(以及其他需要这些作用域的 API 方法)但我无法得到成功的响应,我认为这取决于我发送文件数据的方式.我的代码如下所示:

I am following the process described 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 (and other API methods needing those scopes work) but I can't get a successful response and I think it's down to how I am sending the file data. My code looks like this:

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'
}

身份验证令牌已包含在会话的标头中.以下是上传过程的日志:

The auth token is already included in the session's headers. Here are the logs from the upload process:

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"}

推荐答案

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

We had a sample code with Python in the past with v1 endpoints. I migrated to v2 today. It looks working well. Could you take a look if it could help you to address the issue you are having? https://github.com/xiaodongliang/forge.workflow-python-sample

这篇关于使用 Python 请求将文件数据放入 Autodesk API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆