首页 > 解决方案 > 找不到起始边界

问题描述

描述错误

我被用作aiohttp文件上传的客户端和服务器,当我在 post 请求中添加 headers 时,服务器引发了错误。</p>

Could not find starting boundary b'--dd7db5e4c3bd4d5187bb978aef4d85b1'

重现

环境

蟒蛇:3.7.4

aiohttp: 3.7.4.post0

窗户10

服务器

```python
    ...
    print("Enter form-data")
    print("req header: ", request.headers)
    data = await request.post()
    file_data = data["file"]
 ```

客户

1、不工作

```python
 async with aiohttp.ClientSession() as session:
        async with session.post(
            url='http://{}:{}/mesh/recognize'.format(web_ip, web_port),
            data=file_data,
            headers={'Content-Type': 'multipart/form-data; boundary=dd7db5e4c3bd4d5187bb978aef4d85b1'}
        ) as resp:
 ```

控制台

> Enter form-data
> req header:  <CIMultiDictProxy('Host': '192.168.102.116:8000', 'Content-Type': 'multipart/form-data; boundary=dd7db5e4c3bd4d5187bb978aef4d85b1',  'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Python/3.7 aiohttp/3.7.4.post0', 'Content-Length': '364927')>
Could not find starting boundary b'--dd7db5e4c3bd4d5187bb978aef4d85b1'
** predict is Failed **

2、工作

 ```python
 async with aiohttp.ClientSession() as session:
        async with session.post(
            url='http://{}:{}/mesh/recognize'.format(web_ip, web_port),
            data=file_data) as resp:
 ```

控制台

> Enter form-data
>req header:  <CIMultiDictProxy('Host': '192.168.102.116:8000', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'User-Agent': 'Python/3.7 aiohttp/3.7.4.post0', 'Content-Length': '364927', 'Content-Type': 'multipart/form-data; boundary=dd7db5e4c3bd4d5187bb978aef4d85b1')>
out:  torch.float32
Predict result :tensor([[[0.0000, 0.0000, 0.0000,  ..., 0.0000, 0.0000, 0.0000],
         [5.0122, 4.7581, 4.8532,  ..., 4.7490, 4.6256, 4.8851]]]),
run time is 3054.393768310547ms
** predict is Successed! **

标签: aiohttp

解决方案


推荐阅读