Skip to content
Discussion options

You must be logged in to vote

@OscamSatUser I think the confusion is that your original problem was the same as @davefes -- you have a bytes/bytearray containing non-utf-8 data, and actually you're first use your byte2string function, then use ascii_only on the result. Not just the ascii_only function.

However, the effect of using both functions is that any non-ascii byte in the input is first turned into the utf-8 representation (i.e. 0xa0 becomes 0xc2 0xa0), and then ascii_only implicitly converts this back to bytes, to exclude the non-ascii bytes.

As @karfas points out, the simpler solution is to just filter out the bytes, then decode the now-sanitised bytes. @karfas I think you meant to write "".join(chr(c) for c …

Replies: 4 comments 7 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@GitHubsSilverBullet
Comment options

Comment options

You must be logged in to vote
6 replies
@davefes
Comment options

@karfas
Comment options

@OscamSatUser
Comment options

@jimmo
Comment options

Answer selected by OscamSatUser
@OscamSatUser
Comment options

@davefes
Comment options

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