我正在尝试使用可以从图像中检测人脸的 API。我正在使用 Python 并希望能够上传指定参数的图像(在控制台中)。例如:
python detect.py jack.jpg
这意味着将文件jack.jpg发送到 API。然后打印JSON响应。这是识别人脸的 API 的文档。
http://rekognition.com/developer/docs#facerekognize
下面是我的代码,我使用的是 Python 2.7.4
#!/usr/bin/python
# Imports
import sys
import requests
import json
# Facedetection.py sends us an argument with a filename
filename = (sys.argv[1])
# API-Keys
rekognition_key = ""
rekognition_secret = ""
array = {'api_key': rekognition_key,
'api_secret': rekognition_secret,
'jobs': 'face_search',
'name_space': 'multify',
'user_id': 'demo',
'uploaded_file': open(filename)
}
endpoint = 'http://rekognition.com/func/api/'
response = requests.post(endpoint, params= array)
data = json.loads(response.content)
print data
我可以看到一切看起来都很好,但是我的控制台得到了这个输出:
Traceback (most recent call last):
File "upload.py", line 23, in <module>
data = json.loads(response.content)
File "/usr/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 383, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
怎么了?