khl.py icon indicating copy to clipboard operation
khl.py copied to clipboard

上传mp4文件的时候报错

Open Because66666 opened this issue 1 year ago • 0 comments

Describe the bug 场景:使用bot.client.create_asset上传视频.mp4文件的时候报错。 报错内容:Requesting 'POST asset/create' failed with 40000: Width必须是整数。 报错堆栈:Traceback (most recent call last): File "C:\Users\Administrator\Downloads_***_bots\kook_bot\kook_bot.py", line 207, in h4 file_url = await bot.client.create_asset(path_to_load) # 上传测试文件 File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\khl\client.py", line 126, in create_asset return (await self.gate.exec_req(api.Asset.create(file=f)))['url'] File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\khl\gateway.py", line 30, in exec_req return await self.requester.exec_req(r) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\khl\requester.py", line 48, in exec_req return await self.request(r.method, r.route, **r.params) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\khl\requester.py", line 39, in request raise HTTPRequester.APIRequestFailed(method, route, params, rsp['code'], rsp['message']) khl.requester.HTTPRequester.APIRequestFailed: Requesting 'POST asset/create' failed with 40000: Width必须是整数。

Expected behavior 正常的上传文件

Environment

  • Python version:3.10.9
  • khl.py version:0.3.17
  • OS:windows

报错分析 传递给服务器中的请求的headers中content-type字段缺少boundary字段,原因是khl/requester.py中的第471行为 @req('POST', headers={'Content-Type': 'multipart/form-data'}) 指定了content-type。

推荐解决办法@req('POST', headers={'Content-Type': 'multipart/form-data'})改为@req('POST'),此时程序会自动指定content-type字段

Because66666 avatar May 28 '24 14:05 Because66666