aiohttp - 找不到起始边界
问题描述
描述错误
我被用作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! **
解决方案
推荐阅读
- android - 单击底部导航时,仅第一个和最后一个片段发生变化
- javascript - simple-git:使用 simple-git 的 SSH 身份验证示例
- r - 如何使用 dplyr 库将三个数据集放在一起并提供基于相似案例的订单?
- amazon-web-services - AWS - 服务器到服务器发布-订阅
- google-cloud-platform - 在 bigquery DTS 中将用户帐户更新为服务帐户
- python - 如何将大数据框与小数据框合并?
- swift - 从 SceneKit 中的 SCNGeometry 中提取人脸信息
- node.js - 在构建期间继续编码/开发正在构建 Angular 2+
- c# - 如何使用 c# 运行 sqlite3 内联命令?
- asp.net-mvc - 使用分页符在单个 Word 文档中导出多个 MVC 视图