0

I have this error in my /etc/i3blocks.conf

Error: Could not parse JSON (lexical error: invalid bytes in UTF8 string.)

My code in /etc/i3blocks.conf looks like this.

[rss]
command=rsstail -n1 -1 -N -u https://stackexchange.com/feeds/questions | head -c 50
color=#00FF00
interval=300

[rss]
command=rsstail -n1 -1 -N -u https://unix.stackexchange.com/feeds | head -c 50
color=#00FF00
interval=60

[rss]
command=rsstail -n1 -1 -N -u https://softwarerecs.stackexchange.com/feeds | head -c 50
color=#00FF00
interval=300

[rss]
command=rsstail -n1 -1 -N -u https://news.ycombinator.com/rss | head -c 50
color=#00FF00
interval=300

It's because RSS title contains not allowed characters. Otherwise I have not this error. How can I fix or handle this error in my /etc/i3blocks.conf? So that, if one RSS channel doesn't work, the other three will work?

4
  • Try setting the locale to a utf8 variant, eg command=LC_ALL=en_GB.utf8 rsstail ....
    – meuh
    May 6 at 18:32
  • @meuh After i3-msg restart I have the same error. Shouldn't second = be excaped somehow?
    – xralf
    May 6 at 18:53
  • 1
    I don't see any examples where the = is escaped. You might try piping the rsstail output through iconv -f UTF-8 -t ASCII//TRANSLIT, which should replace the bad code with something in ascii. If you prefer use iso-8859-15 instead of ascii. Do this before the head. Note: head might cause a problem as it could cut off a utf8 sequence of bytes at midpoint, creating a bad codepoint, hence the value in converting to an encoding that only uses 1 byte per char.
    – meuh
    May 6 at 19:31
  • @meuh This helped. Thank you.
    – xralf
    May 6 at 19:42

1 Answer 1

2

The head -c 50 might cause a problem as it could cut off a utf8 sequence of bytes at midpoint, creating a bad codepoint. If you need to use it you can instead convert the multichar output to an encoding that only uses 1 byte per char, such as ascii or iso-8859-15.

It might be enough to just set this in the locale environment to rsstail:

command=LC_ALL=iso-8859-15 rsstail ...

Alternatively, if there really is bad code coming from rsstail, and assuming the output from rsstail is probably in utf8, you can pipe the output through iconv, asking it to transliterate the bad code with something else:

command=rsstail ... | iconv -f UTF-8 -t iso-8859-15//TRANSLIT | head ...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .