Close

400 {"error":"ERROR_MEDIA_DATA"...........

Anything and everything related to using Sighthound Cloud

Moderator: Staff

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Wed Jun 21, 2017 3:19 pm

I have been trying to get the python example working following the tutorial.
After a number of hours trying to find the reason to the error I give up and ask the question here.

When running the code this is what I get

Step 1: Uploading training images
Adding images for object id Abby
Uploading file IMG_9187.jpg
400 {"error":"ERROR_MEDIA_DATA","reason":"Cannot identify image format","reasonCode":40012,"details":{"statusCode":406,"statusMessage":"Cannot identify image format","body":"image error cannot identify image file (-6)"}}

I've checked Pillow separately and it works and i've checked my Token, so this has to be some other problem.
I can see 400 (bad request?) and 406 (Not acceptable?), is the dev.sighthoundapi.com down? Or is there any other problems?!

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Wed Jun 21, 2017 3:45 pm

Trying this one (where I've changed the cloud token of course) works only with hosted images, but not local jpg files.

Code: Select all
import base64
import httplib
import json
import os
import ssl

headers = {"Content-type": "application/json",
           "X-Access-Token": "YOUR-CLOUD-TOKEN"}
conn = httplib.HTTPSConnection("dev.sighthoundapi.com",
       context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))

# To use a hosted image uncomment the following line and update the URL
#image_data = "http://example.com/path/to/hosted/image.jpg"

# To use a local file uncomment the following line and update the path
#image_data = base64.b64encode(open("/path/to/local/image.jpg").read())

params = json.dumps({"image": image_data})
conn.request("POST", "/v1/detections?type=face,person&faceOption=landmark,gender", params, headers)
response = conn.getresponse()
result = response.read()
print "Detection Results = " + str(result)

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Wed Jun 21, 2017 3:55 pm

OK... changing the following:

Code: Select all
image_data = base64.b64encode(open("/test/face.jpg", "r").read())


with this instead:

Code: Select all
with open("/test/face.jpg", "rb") as f:
    data = f.read()
    #image_data = data.encode("base64")
    image_data = base64.b64encode(data)


works with local files

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Wed Jun 21, 2017 4:04 pm

But how to do it in the Facial Recognition?

User avatar
ryan
 
Posts: 1015
Joined: Wed Aug 25, 2010 2:52 pm
Location: Palo Alto, California

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by ryan » Wed Jun 21, 2017 4:33 pm

Hi gadu,

To perform a recognition request it is the same but with a path that looks like "/v1/recognition?groupId=XXXXX" rather than the "/v1/detections?type=face" you are using now. If you are attempting to do facial recognition against our celebrity data set you can use "/v1/recognition?groupId=_celebrities".

To perform facial recognition against your own data set you must first:
  • Create an object for each person you would like to recognize and upload a set of images for that person
  • Create a new group and add the desired person objects
  • Train the group. After the training call you are ready to make custom recognition calls
After the group has been trained you can perform recognition calls. A full tutorial can be found here.
Learn more about Sighthound Video in our support pages - Reference Guide | All Articles
Are you a developer? Check out our cloud APIs - Demo | Docs

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Thu Jun 22, 2017 2:17 am

@ryan Thanks for the information, i'm fully aware of how to create objects, groups and make the requests. The problem is the error message I get when I use your python tutorial to upload training images from the training folder.

When running the pythoncode from the tutorial, this is the error message I get

Step 1: Uploading training images
Adding images for object id Abby
Uploading file IMG_9187.jpg
400 {"error":"ERROR_MEDIA_DATA","reason":"Cannot identify image format","reasonCode":40012,"details":{"statusCode":406,"statusMessage":"Cannot identify image format","body":"image error cannot identify image file (-6)"}}

User avatar
ryan
 
Posts: 1015
Joined: Wed Aug 25, 2010 2:52 pm
Location: Palo Alto, California

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by ryan » Thu Jun 22, 2017 2:18 pm

This is the same error you were receiving during file upload on your earlier detection calls so things should work if you modify the image upload code in the same way.

What platform and python version are you using? That error message was generated on the second image file upload, it's interesting that you didn't have a similar issue with the first file.
Learn more about Sighthound Video in our support pages - Reference Guide | All Articles
Are you a developer? Check out our cloud APIs - Demo | Docs

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Sat Jun 24, 2017 6:15 am

@ryan

Thanks I'll do some more testing with upload of the training files.

I'm using Win 7 and Python 2.7

no avatar
gadu
 
Posts: 7
Joined: Wed Jun 21, 2017 3:04 pm

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by gadu » Sat Jun 24, 2017 12:13 pm

Ok, So I tested just quickly on a Raspberry Pi and it worked fine, uploads training images as it should. But still not on my laptop with win7.

User avatar
ryan
 
Posts: 1015
Joined: Wed Aug 25, 2010 2:52 pm
Location: Palo Alto, California

Re: 400 {"error":"ERROR_MEDIA_DATA"...........

by ryan » Mon Jun 26, 2017 4:06 pm

Windows differentiates between text files and binary files while other operating systems such as linux and macOS do not. You are seeing the same error you did in your original detection requests and will need to make the same change to the image upload code, opening the image files with "rb" rather than "r" alone. I'll suggest to the team that the python samples are updated accordingly.
Learn more about Sighthound Video in our support pages - Reference Guide | All Articles
Are you a developer? Check out our cloud APIs - Demo | Docs


Return to API Discussion