我正在尝试使用请求工具栏上传巨大的文件。使用Python Bottle框架从HTML表单收集文件
uploadfile = request.files.get('File Upload')
payload = MultipartEncoder({uploadfile.filename:uploadfile.file.read()})
r = requests.post(url,
files=payload,auth=(username,password))
错误
TypeError: 'MultipartEncoder' object is not iterable
题:
1.如何发送收集到的文件对象?
最佳答案
当使用MultipartEncoder
时,我将信息作为data
属性发送,如其示例所示:
https://pypi.python.org/pypi/requests-toolbelt/0.3.0
这是我将使用的示例脚本:
from requests_toolbelt import MultipartEncoder
import requests
uploadfile = open("./example_upload.dat", "r")
payload = MultipartEncoder({uploadfile.name: uploadfile})
r = requests.post(
"http://example.com",
data=payload,
auth=("exampleuser","examplepassword"),
headers={"Content-Type": payload.content_type})
关于python - 请求工具带上传大文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28589782/