问题描述
Error handling request
Traceback (most recent call last):
File "F:\Anaconda\lib\site-packages\aiohttp\web_protocol.py", line 418, in start
resp = await task
File "F:\Anaconda\lib\site-packages\aiohttp\web_app.py", line 458, in _handle
resp = await handler(request)
File "F:\Anaconda\lib\site-packages\aiohttp\web_middlewares.py", line 119, in impl
return await handler(request)
File "F:\任务自动化\evn\middleware.py", line 15, in findRoot
response = await handler(request)
File "F:\Anaconda\lib\site-packages\aiohttp_session\__init__.py", line 152, in factory
response = await handler(request)
File "F:\Anaconda\lib\site-packages\aiohttp\web_urldispatcher.py", line 890, in _iter
resp = await method()
File "F:\任务自动化\app\automatedTask\views\user.py", line 56, in post
return await getattr(self, self.request.match_info.get("method"))(data)
File "F:\任务自动化\app\automatedTask\views\project.py", line 46, in addProj
uploadFile = await data.next()
File "F:\Anaconda\lib\site-packages\aiohttp\multipart.py", line 561, in next
await self._read_until_first_boundary()
File "F:\Anaconda\lib\site-packages\aiohttp\multipart.py", line 627, in _read_until_first_boundary
% (self._boundary))
ValueError: Could not find starting boundary b'------WebKitFormBoundaryeVkJyLKSiXXP1UA2'
当前台向后台上传文件时(分段上传),后台出现上传文件内容为空的情况,
Request Handler:
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 268
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryHd2De0BjpWABxVOL
Cookie: AIOHTTP_APP_SET="gAAAAABdKxlC5Pf_lq1T82VRPgJR70M1NKsC0Y8O83ygUqhYjeeYsYKlZM67DjXAfPMO3uSaoNjB1oAeiMo79AWSn3HFaOxxnqzDi9I6LaLEi9QBWuWUx2QAmbzcCGVG3xbSxBTfmX4BIuJaSUsHPXXfuBMf58U8GP-ALflIuIhOnqjMQ_CtXQpEa92e8c5OgRQozaslvMyQ8_EjAwhLMtEqCZSggutF86HDd6AFiAzMkOfJtiD6gJA="
Host: 127.0.0.1:10000
Origin: http://127.0.0.1:10000
Pragma: no-cache
Referer: http://127.0.0.1:10000/automatedTask
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36
经研究为 aiohttp StreamReader 会调用 readany 方法读取数据(collections.deque())就会造成数据丢失,所以当数据为上传数据时(当为普通的 POST 请求时还需要读取数据),则将不进行数据读取操作,就能解决问题。
修改方案
找到对应的 Python 依赖包安装环境(/usr/local/lib/pythonX.X/dist-packages) 下的 aiohttp, 将 streams.py 复制到 aiohttp 目录下
因无法上传文件, 所以 streams.py 内容的详细请参见 我的位置笔记