2012-05-08 62 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的參數)。