我正在尝试通过遍历 csv 文件来上传多个文件。文件第一行的内容被上传,然后我得到Remote end closed connection with response error。我尝试将 User-Agent 添加到标题中,如与此类问题相关的其他答案中所述,但它不起作用。第一行的内容也被上传了两次,我不知道为什么。
这部分脚本涉及到 headers 和 http 请求
body = b'\r\n'.join(dataList)
payload = body
headers = {
'userId': '1055',
'Authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiJudWxsIiwiREJJZCI6IjEwNTUiLCJGaXJzdE5hbWUiOiJQYW5rYWoiLCJUZW5hbnRDb2RlIjoiaW5maW5pdHlsZWFybiIsIkxhc3ROYW1lIjoiR295YWwiLCJleHAiOjE2NDMxODA1MDksImlhdCI6MTY0MzA5NDEwOX0.hQs0AcJ6oRXXpkfK8dEd-QVa8skKpZj6GUg6ZXjwMQo',
'Content-type': 'multipart/form-data; boundary={}'.format(boundary),
'User-Agent':"Mozilla/5.0"
}
conn.request("POST", "/videos/add_video", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
time.sleep(1)
这是堆栈跟踪
Traceback (most recent call last):
File "http_upload.py", line 104, in <module>
res = conn.getresponse()
File "/usr/lib64/python3.7/http/client.py", line 1369, in getresponse
response.begin()
File "/usr/lib64/python3.7/http/client.py", line 310, in begin
version, status, reason = self._read_status()
File "/usr/lib64/python3.7/http/client.py", line 279, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response