【发布时间】:2014-04-03 22:34:12
【问题描述】:
我正在尝试上传文件,使用 requests 库提交 POST。
这很好用:
theFile = { 'LUuploadFile': ("linea.ipa", open(path_to_file, 'rb'), 'application/octet-stream') }
request = requests.post(url, files=theFile)
这会引发错误:
theFile = { 'LUuploadFile': ("línea.ipa", open(path_to_file, 'rb'), 'application/octet-stream') }
request = requests.post(url, files=theFile)
错误很奇怪:
( <class 'requests.exceptions.ConnectionError'>,
ConnectionError(MaxRetryError("HTTPSConnectionPool(host='fupload.apperian.com', port=443):
Max retries exceeded with url: /upload?transactionID=...
(Caused by <class 'socket.error'>: [Errno 32] Broken pipe)",),),
<traceback object at 0x100a8e3f8>)
这不是服务器,如果我使用curl,它会接受文件名:
curl --form "LUuploadFile=@línea.ipa" http://...
【问题讨论】:
-
我猜
requests将 í 字符作为 UTF-8 编码直接放入套接字中,作为Content-Disposition标头的一部分,这是不允许的。您是否尝试过对文件名进行百分比编码? -
@univerio - 实际上,这正是
curl所做的。requests编码为filename*=utf-8''li%CC%81nea.ipa(rfc5987),服务器可能不支持... -
工作行和不工作行的区别在于工作行是指
linea,带有小写的i,而一次不工作的行是línea,带有重音符号在 i 上。差异在我的屏幕上不是很明显。 -
@mata - 你是说
curl使用百分比编码,但requests没有? -
@egrunin - 不,恰恰相反,
curl是不编码文件名并将其作为原始 utf8 发送的那个...
标签: python python-requests python-unicode