我使用Python的cgi模块解析多部分/表单输入:
body_file = StringIO.StringIO(self.request.body)
pdict = {'boundary': 'xYzZY'}
httpbody = cgi.parse_multipart(body_file, pdict)
text = self.trim(httpbody['text'])
我想打印一些UTF-8编码的httpbody元素。
我尝试了text.decode('utf-8')
和unicode(text, encoding='utf-8')
,但似乎没有任何效果。我在这里错过了什么吗?
答案 0 :(得分:0)
尝试以下方法:
text = self.trim(httpbody['text'])
text.encode('utf-8')
我假设text
变量在字符串中,如果不确定str()
。否则,您将收到另一个错误。