2012-05-08 30 views
0

我正尝试将图像上传到Face.com API。它要么为图像提供url,要么可以直接上传图像。 Their website说:Face.com API从python上传图像

该上传相片

A请求必须被形成为使用POST数据发送的MIME多部分 消息。应将每个参数(包括原始图像 数据)指定为单独的表单数据块。

问题是,我不确切地知道这意味着什么。现在我的代码如下所示:

import urllib 
import json 

apikey = "[redacted]" 
secret = "[redacted]" 

img = raw_input("Enter the URL of an image: "); 

url = "http://api.face.com/faces/detect.json?api_key=" + apikey + "&api_secret=" + secret + "&urls=" + urllib.quote(img) + "&attributes=all" 
data = json.loads(urllib.urlopen(url).read()) 

如何将其转换为与本地存储的图像一起使用?

+0

使用请求:http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file –

回答

1

将照片上载到face.com API的最简单方法是使用可从http://developers.face.com/download/下载的Python客户端库。

你在那里2。两者都支持通过传递文件名到检测到的方法进行上传(作为不同于url的参数)。