ユーザーから (appengine アプリに) アップロードされたファイルを含めるように、要求ライブラリ ドキュメントの例を変更しようとしています。私は次のことを試しました:
from libs import requests
file_data = self.request.POST['file_to_upload']
the_file = file_data
send_url = "http://httpbin.org/post"
values = {
'user_id' : '1234',
'file_name' : 'some_file.pdf'
}
r = requests.post(send_url, files=the_file)
logging.info(r.content)
ただし、これは戻ります
{
"origin": "81.178.201.22",
"files": {},
"form": {},
"url": "http://httpbin.org/post",
"args": {},
"headers": {
"Content-Length": "0",
"Accept-Encoding": "identity, deflate, compress, gzip",
"Connection": "keep-alive",
"Accept": "*/*",
"User-Agent": "python-requests/0.11.1 AppEngine-Google; (+http://code.google.com/appengine)",
"Host": "httpbin.org",
"Content-Type": ""
},
"json": null,
"data": ""
}
つまり、受信したファイルはありません。また、the_fileを次のように送信しようとしました
file_data.file
file_data.file.read()
ただし、これらも失敗します。最終的には、「値」とファイルの両方を同じ投稿リクエストに含めたいので、次のようにします。
r = requests.post(send_url, data=values, files=the_file)
ただし、これも機能していません。最初に上記のコードを修正する必要があると思います。私が間違っていることについて何か考えはありますか?