c by requests(Python 2.7)で画像ファイルを取得し、postメソッドを使用してサーバーに送信しますか?
file = requests.get('http://site.com/immage.jpg')
requests.post('http://site2.com/, file=somefile')
に変換する方法file
はsomefile
?
c by requests(Python 2.7)で画像ファイルを取得し、postメソッドを使用してサーバーに送信しますか?
file = requests.get('http://site.com/immage.jpg')
requests.post('http://site2.com/, file=somefile')
に変換する方法file
はsomefile
?
応答の.content
属性を使用します。
resp = requests.get('http://site1.example.com/immage.jpg')
requests.post('http://site2.example.com/, files=dict(file=resp.content))
ダウンロードした画像を、フィールド名がマルチパートエンコードされたPOSTfile
として投稿しました。それはあなたが彼らが期待するフィールド名に投稿している正確なアプリケーションに依存します。
うーん、あなたはそれを保存します...
with open("somefile.jpg","wb") as f:
f.write(file.content)