tencent-connect / botpy

QQ频道机器人PythonSDK
MIT License
477 stars 81 forks source link

await message.reply()发送本地图片报错 #129

Open myrechen opened 1 year ago

myrechen commented 1 year ago

运行环境: win10, py3.8.6

问题描述: 在使用该api发送包含图片的信息时, 有概率出现"upload image error", 错误号: 500; 我不确定是哪里出了问题, 因为重新发送命令@机器人又可以收到图片信息, 但这个错误会不时地出现

调用方式:

filename = "xxx.jpg"
with open(filename, "rb") as img:
    img_bytes = img.read()
await message.reply(content=f"xxxxxx", file_image=img_bytes)

错误信息:

[ERROR] (http.py:73)_handle_response    [botpy] 接口请求异常,请求连接: https://api.sgroup.qq.com/channels/1xxxxxxxx/messages, 错误代码: 500, 
返回内容: {'code': 304017, 'message': 'upload image error'}, trace_id:0f08db94515b223207dd481c18b58f6b
Traceback (most recent call last):
  File "D:\Python\Python-3.8.6\lib\site-packages\botpy\client.py", line 279, in _run_event
    await coro(*args, **kwargs)
  File "d:\qqbot\sample1.py", line 36, in on_at_message_create
    await message.reply(content=f"{parseResult[2]}", file_image=img_bytes)
  File "D:\Python\Python-3.8.6\lib\site-packages\botpy\message.py", line 84, in reply
    return await self._api.post_message(channel_id=self.channel_id, msg_id=self.id, **kwargs)
  File "D:\Python\Python-3.8.6\lib\site-packages\botpy\api.py", line 508, in post_message
    return await self._http.request(route, json=payload)
  File "D:\Python\Python-3.8.6\lib\site-packages\botpy\http.py", line 186, in request
    return await _handle_response(response)
  File "D:\Python\Python-3.8.6\lib\site-packages\botpy\http.py", line 83, in _handle_response
    raise error_dict_get(msg=message) from None
botpy.errors.ServerError: upload image error
myrechen commented 1 year ago

我希望获取到这个错误并处理重新发送图片,我应该如何获取这些信息:

错误代码: 500, 
返回内容: {'code': 304017, 'message': 'upload image error'}
Gintamashiichan commented 1 year ago

Use async instead of sync :)

SaucePlum commented 1 year ago

Please try to replace smaller local images for testing. The problem that may occur is basically caused by your insufficient bandwidth

Suz1e commented 1 month ago

解决问题了嘛