Search code examples
pythonpylint

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.


Solution

  • 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.