【发布时间】:2020-08-11 02:26:40
【问题描述】:
我正在使用 python 将一些 .jpg 图像上传到我创建的照片场景,但我不断收到此错误。
{'Usage': '0.48637413978577', 'Resource': '/file', 'Error': {'code': '19', 'msg': "Specified Photoscene ID doesn't exist in the database"}}
这是我的代码,photoscene 创建效果很好,我获取了photoscene id 并将其复制为字符串以将其存储为“sceneId”
formData = {'Content-Type': 'multipart/form-data', 'Authorization': 'Bearer eyXXXX'}
sceneId = "l5w----etc-etc------qQ"
# This bit is so I can use tkinter to choose my images
application_window = tk.Tk()
application_window.withdraw()
answer = filedialog.askopenfilenames(parent=application_window,
initialdir=os.getcwd(),
title="Please select one or more files:",
filetypes=[("Image files", ".jpg .jpeg")])
if answer != "":
files = {
"photosceneid":(None, sceneId),
"type":(None, "image")
}
n=-1
for a in answer:
n = n+1
a = a.replace("/", "//")
files["file[{x}]".format(x=n)] = (a, open(a,"rb"))
# This bit adds keys and values to the dictionary as "file[0]": ("path//to//image//", open("path//to//image//","rb"))
r = requests.post("https://developer.api.autodesk.com/photo-to-3d/v1/file",headers=formData,files=files).json()
print(r)
我在关注官方api reference的截图
curl -v 'https://developer.api.autodesk.com/photo-to-3d/v1/file' \
-X 'POST' \
-H 'Authorization: Bearer eyjhbGCIOIjIuzI1NiISimtpZCI6...' \
-F "photosceneid=hcYJcrnHUsNSPII9glhVe8lRF6lFXs4NHzGqJ3zdWMU" \
-F "type=image" \
-F "file[0]=@c:/sample_data/_MG_9026.jpg" \
-F "file[1]=@c:/sample_data/_MG_9027.jpg"
感谢您的阅读和帮助!
【问题讨论】:
-
创建场景时响应中的输出是什么?有任何错误信息吗?
-
只有200回复:
{'Usage': '0.63232898712158', 'Resource': '/photoscene', 'Photoscene': {'photosceneid': 'XX'}}我今天尝试删除photoscene并没有问题,甚至尝试删除它两次以防万一但photoscene不存在(因为我刚刚删除了它),所以它正在工作,也许需要一些时间来处理照片场景? -
同样 GET 进度返回一个成功的响应 {'Usage': '0.57368898391724', 'Resource': '/photoscene/XX/progress', 'Photoscene': {'photosceneid': 'XX', 'progressmsg': 'Created', 'progress': '0'}} 也许是上传端点的问题我最怀疑我的文件字典,我认为是格式导致了问题。更改无效参数的参数会给出相同的错误响应(没有具有该 ID 的 PS)
-
如果有目的,这是我在创建场景时发送的数据
data = {'scenename': 'FirstTest', 'callback': 'email://my@email.com', 'format': 'rcm', 'scenetype': 'object', 'version': '2.0'}
标签: python python-requests autodesk-forge autodesk-realitycapture