在str.decode中使用的Pylint抛出非文本编码

时间:2019-05-15 12:05:33

标签: python pylint

我在代码中包含以下行:

decoded_url = url.decode('base64')

我运行pylint --py3k <path_to_file>时会引发以下警告:

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

我尝试搜索,但找不到任何具体内容。

1 个答案:

答案 0 :(得分:1)

您可以使用方法.decode将编码为Latin-1或Windows-1252或UTF-8的字节字符串转换为Unicode。这是因为这些编解码器都具有表示ascii字符集中没有的字符的不同方式。

但是base-64是 encoding 一词的完全不同的含义。要解码base-64字符串,请执行以下操作:

import base64
base64.b64decode(url)

pylint只是告诉您您在不适当的上下文中使用base64