1
$ curl -X POST "https://api- 
us.faceplusplus.com/facepp/v3/detect" -F 
"api_key=<api key>" \
-F "api_secret<api secret>" \
-F "image_url=<顔の入った写真のURL>" \
-F "return_landmark=1"

Hello, I am trying to write an equivalent python requests code for the above but I keep getting errors.

import requests
import json

API_KEY = "--------------"
API_SECRET = "-----------"
image_path="/Users/dukeglacia/Downloads/test_images2/eo.jpg"
vision_base_url="https://api-us.faceplusplus.com/facepp/v3/detect"

response = requests.post(
    vision_base_url,
    {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        # 'image_url': img_url,
        'image_file': image_path,
        'return_landmark': 1,
        'return_attributes': 'headpose,eyestatus,emotion,ethnicity,beauty,facequality,mouthstatus,eyegaze,gender,age,smiling'

    }
)

analysis = response.json()
print (analysis)

My error says that the arguments image_file not found. But as shown in the code below I have included the arguments.

5
  • Where the actual error you get from ? from python code or from the API endpoint ? I tried your python code and seems to send almost same request as curl except that Content-Type is multipart/form-data in curl but application/x-www-form-urlencoded in python Commented Sep 21, 2018 at 6:38
  • So if that difference is the problem, you may try stackoverflow.com/questions/12385179/… Commented Sep 21, 2018 at 6:40
  • This is my error Commented Sep 21, 2018 at 6:44
  • {'time_used': 65, 'error_message': 'MISSING_ARGUMENTS: image_url, image_file, image_base64', 'request_id': '1537512382,040315b2-25b5-41c7-92a7-5aa5a731b344'} Commented Sep 21, 2018 at 6:46
  • So I think there is a error on the API side Commented Sep 21, 2018 at 6:46

1 Answer 1

1

According to FacePlusPlus's documentation, image_file should be a file instead of a path, so you should post the file binary with:

response = requests.post(
    vision_base_url,
    {
        'api_key': API_KEY,
        'api_secret': API_SECRET,
        'return_landmark': 1,
        'return_attributes': 'headpose,eyestatus,emotion,ethnicity,beauty,facequality,mouthstatus,eyegaze,gender,age,smiling'

    },
    files={'image_file': open(image_path, 'rb')}
)

Please refer to requests's documentation for more details of how you can upload a file.

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.