python - 如何使用 aiohttp multipartwriter 发送图像?
问题描述
我正在尝试使用不和谐机器人将图像作为消息发送。我期待得到这样的东西,但我得到
Cannot create payload from {'name': 'file', 'value': <_io.BufferedReader name='./emojis/1f92f.png'>, 'filename': '1f92f.png', 'content-type': 'application/octet-stream'}
当我使用这个时:
file = open(f'./emojis/{final_point}.png', 'rb')
writer = aiohttp.multipart.MultipartWriter('form-data', boundary='--boundary--')
writer.append({'content_type': 'application/octet-stream', 'name': f'{final_point}.png','value': file})
async with aiohttp.ClientSession() as session:
await session.post(f'{util.url}/interactions/{interaction.id}/{interaction.token}/callback', data=writer)
[400 Bad Request]
当我使用它时,我得到了:
file = open(f'./emojis/{final_point}.png', 'rb')
writer = aiohttp.multipart.MultipartWriter('form-data', boundary='--boundary--')
writer.append(file, {'CONTENT-TYPE': 'image/png'})
async with aiohttp.ClientSession() as session:
await session.post(f'{util.url}/interactions/{interaction.id}/{interaction.token}/callback', data=writer)
有人有解决方案吗?
解决方案
推荐阅读
- r - 使用 EDGAR 在 R 中的 For-Loop 中创建变量的问题
- javascript - 将 Electron 应用程序打包到 macOS 时出错
- c - 蜂鸣器 持续蜂鸣 HIGH 然后 LOW
- java - 如何在Android中将HTML页面下载为pdf?
- opencv - 获得清晰和连续轮廓opencv的问题
- python - 如何更正要在 python 中执行的 sql 查询?
- java - 在 docker 容器内生成的 Log4j 日志
- angularjs - 禁用日期字段
- java - 编写可测试的代码 - Junit Test
- aws-cli - 如何使用多个负载均衡器创建 aws fargate 服务