1

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.

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.