Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
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

Fix: 修复在使用file_image时,请求中的msg_id和content等字段失效 #50

Merged
merged 4 commits into from
Aug 31, 2023

Conversation

iRis7656
Copy link
Contributor

修复在使用file_image时,请求中的msg_id和content等字段丢失。这个问题会导致文本消息未发送或消息被识别为主动消息的情况

修复在使用file_image时,msg_id和content等字段丢失,导致文本消息未发送和被识别为主动消息的情况
@yanyongyu
Copy link
Member

@iRis7656
Copy link
Contributor Author

我的修改确实是不对的。但我发现data_[k] = (None, v.encode("utf-8"), "text/plain")中,encode后的字段没有被正常识别,不进行encode直接传入v消息正常。如图,上为原代码,下为删去encode后效果:
Screenshot_20230824_161128

@iRis7656 iRis7656 changed the title 修复在使用file_image时,请求中的msg_id和content等字段丢失 修复在使用file_image时,请求中的msg_id和content等字段失效 Aug 24, 2023
@yanyongyu
Copy link
Member

yanyongyu commented Aug 24, 2023

如果要改成str的话需要修改nb本体,能否尝试最新nb master分支是否能发送encode后的内容

@yanyongyu
Copy link
Member

yanyongyu commented Aug 24, 2023

看了下httpx源码,不管有没有encode最后都是会encode一下变成utf8 bytes的

https://github.com/encode/httpx/blob/0f61aa58d66680c239ce43c8cdd453e7dc532bfc/httpx/_multipart.py#L170-L173

@iRis7656
Copy link
Contributor Author

我换成最新master分支是一样的结果。既然都会encode这就很奇怪了,删掉确实有效果,希望能找到真正的解决办法吧。之前有群友也遇到一样的情况

@yanyongyu
Copy link
Member

你是使用的httpx还是aiohttp

@iRis7656
Copy link
Contributor Author

这个是可以自己选的嘛,是指驱动器?只开启了DRIVER=~aiohttp

@yanyongyu
Copy link
Member

你尝试一下使用httpx

@iRis7656
Copy link
Contributor Author

换成DRIVER=~httpx+~websockets后原代码正常运行了

@yanyongyu
Copy link
Member

那看来是aiohttp这边的问题

@yanyongyu
Copy link
Member

@yanyongyu
Copy link
Member

yanyongyu commented Aug 27, 2023

看了下aiohttp在value是bytes,filename为none的时候会设置为field name,可能是这个问题

https://github.com/aio-libs/aiohttp/blob/db2c274c91d17eb410225d504c83d4bd6971d0ae/aiohttp/formdata.py#L56-L58

@yanyongyu
Copy link
Member

破案了,就是aiohttp自动给bytes类型的字段加了filename导致频道丢了这部分内容

@yanyongyu yanyongyu added the bug Something isn't working label Aug 31, 2023
@yanyongyu yanyongyu changed the title 修复在使用file_image时,请求中的msg_id和content等字段失效 Fix: 修复在使用file_image时,请求中的msg_id和content等字段失效 Aug 31, 2023
@yanyongyu yanyongyu merged commit c53a308 into nonebot:master Aug 31, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

4 participants