I have tried to use the Detection API but I had an error. I am new in coding
I am using python 3 and I replaced httplib for http.client and I want to test with images from my computer (MAC)
This is my code:
- Code: Select all
import base64
import http.client
import json
import os
import ssl
headers = {"Content-type": "application/json",
"X-Access-Token": "60Lixxxxxxxxxxxxxxxxxxxx"}
conn = http.client.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("/Users/julius/Desktop/prueba1.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))
And the error is this:
Traceback (most recent call last):
File "<ipython-input-15-9ec7afe59fc8>", line 10, in <module>
image_data = base64.b64encode(open("/Users/julius/Desktop/prueba1.jpg").read())
File "/Users/julius/anaconda/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)
Thank you!
julius
