Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

上传mp4文件的时候报错 #234

Open
Because66666 opened this issue May 28, 2024 · 0 comments
Open

上传mp4文件的时候报错 #234

Because66666 opened this issue May 28, 2024 · 0 comments

Comments

@Because66666
Copy link

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字段

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant