3

I have a cURL request that is working fine.

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

I have a python script where I want to execute the same request. But I get the following error,

{ "error": { "message": "'NoneType' object has no attribute 'iteritems'", "type": "AttributeError" } }

Here is the python code,

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)

Any idea how to properly convert the code? Should I pass file=file in request?

Mujeeb
  • 995
  • 1
  • 8
  • 18

1 Answers1

1

Try this:

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)