weechat/scripts

grep.py UnicodeDecodeError on search

Closed this issue · 5 comments

I'm trying to use grep.py 0.8.2 on weechat 2.6, which worked fine in previous versions. However now when issuing /grep term in any buffer, the result buffer opens in background and I get this error in the core buffer:

12:28 python: stdout/stderr (grep): UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 0: invalid start byte
12:28 =!= python: error in function "grep_process_cb"

how to debug this?

Hi,
Your problem is related to Python 3 which is now enabled in WeeChat (since version 2.6), and the script itself may require some extra changes.
Could you please try with the latest development version? Changes were made about the strings sent to the callbacks in Python scripts, so you could have a different behavior there.

Indeed weechat/weechat@513f5a1 looks like it fixes the behaviour. I can only test with the released version, however, so I'll wait until the next one to check back. Sorry for that, thanks for caring nevertheless!

So I'm closing this issue, it can be reopened if needed.

i'm still getting this on v2.7-rc1-6-gc947d1575 (py3) and 0.8.2 on most buffers

edit: i was using the wrong version of the python plugin

i can't get grep.py to work still. the result variable in grep_process(), for instance,

{'/core.weechat.weechatlog': ["2019-11-29 20:32:33\t[grep]\tSearch for '123' ...9 20:42:06\t[grep]\tSearch for '123' stopped.\n"]}

gets encoded to (output of q)

b"\x80\x03}q\x00X\x18\x00\x00\x00/core.weechat.w...K\x03X\x0e\x00\x00\x00stripped_linesq\tK\x00ubs."

grep_process_cb() then receives, respectively, b'\x80\x03}q' and '' as out and err. i see two problems here:

  • the stdout gets terminated early (due to the null byte?)
  • the stdout/stderr can be either str or bytes, but grep_stdout/grep_stderr is always a str, you can't add the two

i'm not sure how this works for other people and in my opinion it makes little sense for things like grep_process_cb to receive str in the first place