2012-01-25 31 views
1

我已經檢查了很多代碼片段,但我無法得到如何發佈多部分文本和二進制文件在單個請求只有Python 2.4? Here在評論中提到了BytesIO類的一些內容,但不在2.4中。 (普通的Python,沒有第三方庫)謝謝。多部分二進制文件POST在Python 2.4

+1

你看着[海報](http://atlee.ca/software/poster/)? – jterrace

+0

如果沒有第三方沒有辦法做到這一點,我會嘗試挖掘海報來源。但我希望有一種解決方法。 – Oink

回答

0

與Python 2.6,你可以使用請求庫,這裏是代碼段從documentation提取:

>>> url = 'http://httpbin.org/post' 
>>> files = {'report.xls': open('report.xls', 'rb')} 

>>> r = requests.post(url, files=files) 
>>> r.text 
{ 
    "origin": "179.13.100.4", 
    "files": { 
    "report.xls": "<censored...binary...data>" 
    }, 
    "form": {}, 
    "url": "http://httpbin.org/post", 
    "args": {}, 
    "headers": { 
    "Content-Length": "3196", 
    "Accept-Encoding": "identity, deflate, compress, gzip", 
    "Accept": "*/*", 
    "User-Agent": "python-requests/0.8.0", 
    "Host": "httpbin.org:80", 
    "Content-Type": "multipart/form-data; boundary=127.0.0.1.502.21746.1321131593.786.1" 
    }, 
    "data": "" 
} 
+0

我不確定任何版本的請求是否支持Python 2.4。 –

+0

是的,它應該沒有任何依賴。 – Oink

相關問題