我有一个做工精细的卷曲请求。
curl http://localhost:5000/models/images/generic/infer.json -XPOST -F job_id='123' -F dont_resize='dont_resize' -F snapshot_epoch='100' -F image_file='@/home/hellouser/Downloads/infer/Users/User01/Images/tiles/999/00.jpg'`
我有一个python脚本,我想执行同样的要求。但我得到以下错误,
{ “错误”:{ “消息”: “ 'NoneType' 对象没有属性 'iteritems'”, “类型”: “AttributeError的”}}
这里是Python代码,
import requests
data = {
'job_id': '123',
'dont_resize': 'dont_resize',
'snapshot_epoch': '100',
'image_file': '@/home/hellouser/Downloads/infer/Users/User01/Images/tiles/999/00.jpg' }
url = 'http://localhost:5000/models/images/generic/infer.json'
r = requests.post(url=url, data=data)
不知道如何正确地转换的代码?我应该通过file=file
的要求吗?
尝试这个:
data = {
'job_id': '123',
'dont_resize': 'dont_resize',
'snapshot_epoch': '100',
}
files = {
'image_file': open('/home/hellouser/Downloads/infer/Users/User01/Images/tiles/999/00.jpg', 'rb')
}
url = 'http://localhost:5000/models/images/generic/infer.json'
r = requests.post(url=url, data=data, files=files)