derpkitty
derpkitty

Reputation: 11

curl to Python POST request image upload input error

I am trying to convert this curl command :

curl -X POST -F "[email protected]" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces?api_key={apikey}&version=2016-05-20" 

to a python post request.

used this example in the manual but I'm still getting a no files uploaded error.

url = {'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces'}
images= {'images_file': ('prez.jpg', open('prez.jpg', 'rb'))}
payload = {'api_key': {apikey}, 'version':'2016-05-20'}
r = requests.post(url, files = images, params = payload)
print(r.text)

Here is the return from the Watson API:

{
    "error": {
        "code": 400,
        "description": "No images were specified.",
        "error_id": "input_error"
    },
    "images_processed": 1
}

Am I uploading the file correctly? The curl command works fine so it's probably not the image that's the problem.

Upvotes: 1

Views: 493

Answers (1)

Padraic Cunningham
Padraic Cunningham

Reputation: 180391

This should match your curl request.

url = 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces'
images = {'images_file': open('prez.jpg', 'rb')}
payload = {'api_key': "{{{}}}".format(api_key), 'version': '2016-05-20'}
r = requests.post(url, files=images, params=payload)

Upvotes: 1

Related Questions