Python 请求-发布多个文件
在html中:Python 请求-发布多个文件,python,python-requests,Python,Python Requests,在html中: <form action="/addCar" method="post" enctype="multipart/form-data"> many inputs (text, email, etc) <input type="file" accept="image/*" name="files[]"> <input type="file" accept="image/*" name="files[]"> <in
<form action="/addCar" method="post" enctype="multipart/form-data">
many inputs (text, email, etc)
<input type="file" accept="image/*" name="files[]">
<input type="file" accept="image/*" name="files[]">
<input type="file" accept="image/*" name="files[]">
<input type="file" accept="image/*" name="files[]">
<input type="file" accept="image/*" name="files[]">
</li>
</form>
但它只上传2.jpg
。如何修复它
谢谢。您正在覆盖这些名称。让它与众不同:
files = {
'file1': open('img/1.jpg', 'rb'),
'file2': open('img/2.jpg', 'rb')
}
或者将其放在列表中:
files = {
'files': [open('img/1.jpg', 'rb'), open('img/2.jpg', 'rb')]
}
你正在覆盖这些名字。让它与众不同:
files = {
'file1': open('img/1.jpg', 'rb'),
'file2': open('img/2.jpg', 'rb')
}
或者将其放在列表中:
files = {
'files': [open('img/1.jpg', 'rb'), open('img/2.jpg', 'rb')]
}
files={'files':[open('img/1.jpg','rb'),open('img/2.jpg','rb')])
-TypeError:需要字符串或缓冲区
请尝试第一个,我不知道你在做什么样的请求。如果先没有上传图像,你能解释一下你在做什么样的请求,服务器需要什么样的请求吗?files={'files':[open('img/1.jpg','rb'),open('img/2.jpg','rb')]}
-TypeError:expected string或buffer
试试第一个,我不知道你提出了什么样的请求。如果首先-没有上传图像,你能解释一下你提出了什么样的请求,服务器需要什么样的请求吗?你必须发送5个不同的请求才能完成,你不能一次发送所有的请求。所以,我只能发送一个文件?我想是的,request.session
不支持它。您必须发送5个不同的请求才能完成此任务,您不能一次发送所有请求。所以,我只能发送一个文件?我想是这样,request.session
不支持它。