gpt4 book ai didi

python - 使用请求将文件上传到 python-eve

转载 作者:太空狗 更新时间:2023-10-30 02:30:01 24 4
gpt4 key购买 nike

我正在尝试使用请求库将图片上传到 python-eve 服务器。为此,我发送了一个 multipart/form-data 请求。这似乎是我的模式的问题,它看起来像这样:

schema = {
'name': {
'type': 'string',
'required': True
},
'description': {
'type': 'string'
},
'picture': {
'type': 'media'
},
'properties': {
'type' : 'dict'
}
}

请求看起来像这样:

import requests

file = open('/home/user/Desktop/1500x500.jpeg', 'rb')
payload = {'name': 'hello', 'properties': {'status': 'on_hold'}}
r = requests.post("http://localhost:5001/node", data=payload, files={'picture': file})

我得到的是 ResourceInvalid 异常:

ResourceInvalid: Failed. Response status: 422. Response message: UNPROCESSABLE ENTITY. Error message: {"_status": "ERR", "_issues": {"properties": "must be of dict type"}, "_error": {"message": "Insertion failure: 1 document(s) contain(s) error(s)", "code": 422}}

有什么解决办法吗?我是否遗漏了有关请求格式的内容?

最佳答案

像这样的东西应该工作得很好:

import requests

file = open('/home/user/Desktop/1500x500.jpeg', 'rb')
payload = {'name': 'hello'}

r = requests.post("http://localhost:5001/node", data=payload, files={'picture': file})

关于python - 使用请求将文件上传到 python-eve,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29595737/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com