公告
财富商城
积分规则
提问
发文
2019-03-30 21:08发布
Summer. ? 凉城
Possible Duplicate: string encode / decode
Now the subject looks like: =?UTF-8?B?0J/RgNC+0LLQtdGA0LrQsA==?=
The part between =?UTF-8?B? and ?= is a base64-encoded string. Extract that part, and then decode it.
=?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
Output:
Middle: 0J/RgNC+0LLQtdGA0LrQsA== Decoded: Проверка
Maybe you can use decode_header function: http://docs.python.org/library/email.header.html#email.header.decode_header
最多设置5个标签!
The part between
=?UTF-8?B?
and?=
is a base64-encoded string. Extract that part, and then decode it.Output:
Maybe you can use decode_header function: http://docs.python.org/library/email.header.html#email.header.decode_header