2024-09-22 16:40:18 发布
网友
Possible Duplicate:string encode / decode
现在这个主题看起来像: =?UTF-8型?B?0J/RgNC+0LLQtdGA0LrQsA=?=
也许您可以使用decode_header函数:http://docs.python.org/library/email.header.html#email.header.decode_header
=?UTF-8?B?和?=之间的部分是base64编码的字符串。提取那部分,然后解码。
=?UTF-8?B?
?=
import base64 #My buggy SSH account needs this to write unicode output, you hopefully won't import sys import codecs sys.stdout = codecs.getwriter('utf-8')(sys.stdout) encoded = '=?UTF-8?B?0J/RgNC+0LLQtdGA0LrQsA==?=' prefix = '=?UTF-8?B?' suffix = '?=' #extract the data part of the string middle = encoded[len(prefix):len(encoded)-len(suffix)] print "Middle: %s" % middle #decode the bytes decoded = base64.b64decode(middle) #decode the utf-8 decoded = unicode(decoded, 'utf8') print "Decoded: %s" % decoded
输出:
Middle: 0J/RgNC+0LLQtdGA0LrQsA== Decoded: Проверка
也许您可以使用decode_header函数:http://docs.python.org/library/email.header.html#email.header.decode_header
=?UTF-8?B?
和?=
之间的部分是base64编码的字符串。提取那部分,然后解码。输出:
相关问题 更多 >
编程相关推荐