Kishan Mehta
Kishan Mehta

Reputation: 2678

Pylint throwing non-text encoding used in str.decode

I have the following line in code:

decoded_url = url.decode('base64')

when I run pylint --py3k <path_to_file> it throws following warning:

non-text encoding used in str.decode (invalid-str-codec)

I tried searching but couldn't find anything concrete.

Upvotes: 0

Views: 509

Answers (1)

BoarGules
BoarGules

Reputation: 16942

You can use the method .decode to turn bytestrings that are encoded as, say, Latin-1 or Windows-1252 or UTF-8 into Unicode. That is because these codecs all have different ways of representing characters not in the ascii character set.

But base-64 is an entirely different sense of the word encoding. To decode a base-64 string you do this:

import base64
base64.b64decode(url)

pylint is just telling you that you are using base64 in an inappropriate context.

Upvotes: 1

Related Questions