1

c by requests(Python 2.7)で画像ファイルを取得し、postメソッドを使用してサーバーに送信しますか?

file = requests.get('http://site.com/immage.jpg')
requests.post('http://site2.com/, file=somefile')

に変換する方法filesomefile

4

2 に答える 2

3

応答の.content属性を使用します。

resp = requests.get('http://site1.example.com/immage.jpg')
requests.post('http://site2.example.com/, files=dict(file=resp.content))

ダウンロードした画像を、フィールド名がマルチパートエンコードされたPOSTfileとして投稿しました。それはあなたが彼らが期待するフィールド名に投稿している正確なアプリケーションに依存します。

于 2012-09-21T22:47:10.723 に答える
1

うーん、あなたはそれを保存します...

with open("somefile.jpg","wb") as f:
     f.write(file.content)
于 2012-09-21T22:26:21.200 に答える