[ https://issues.apache.org/jira/browse/THRIFT-3721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15186253#comment-15186253 ]
Jason Heimann edited comment on THRIFT-3721 at 3/9/16 1:20 AM: --------------------------------------------------------------- {code} #! /usr/bin/env python2.7 # -*- coding: utf-8 -*- from thrift.protocol.TBinaryProtocol import TBinaryProtocol from thrift.transport.TTransport import TMemoryBuffer from thrift.Thrift import TType class MyThriftClient(object): def __init__(self, prot): self._prot = prot def myStringAPI(self, param): self._prot.writeFieldBegin('param', TType.STRING, 1) self._prot.writeString(param) self._prot.writeFieldEnd() def main(): transport = TMemoryBuffer() protocol = TBinaryProtocol(transport) client = MyThriftClient(protocol) client.myStringAPI(u'三木 昌彦') if __name__ == "__main__": main() {code} Executing the above code yields a UnicodeEncodeError {code} Traceback (most recent call last): File "./thrift_kanji.py", line 28, in <module> main() File "./thrift_kanji.py", line 24, in main client.myStringAPI(u'三木 昌彦') File "./thrift_kanji.py", line 15, in myStringAPI self._prot.writeString(param) File ".../thriftenv/local/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 123, in writeString self.trans.write(str) File ".../thriftenv/local/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 223, in write self._buffer.write(buf) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) {code} was (Author: table-delete): {code} #! /usr/bin/env python2.7 # -*- coding: utf-8 -*- from thrift.protocol.TBinaryProtocol import TBinaryProtocol from thrift.transport.TTransport import TMemoryBuffer from thrift.Thrift import TType class MyThriftClient(object): def __init__(self, prot): self._prot = prot def myStringAPI(self, param): self._prot.writeFieldBegin('param', TType.STRING, 1) self._prot.writeString(param) self._prot.writeFieldEnd() def main(): transport = TMemoryBuffer() protocol = TBinaryProtocol(transport) client = MyThriftClient(protocol) client.myStringAPI(u'三木 昌彦') if __name__ == "__main__": main() {code} Executing the above code yields a UnicodeEncodeError {code} Traceback (most recent call last): File "./thrift_kanji.py", line 28, in <module> main() File "./thrift_kanji.py", line 24, in main client.myStringAPI(u'三木 昌彦') File "./thrift_kanji.py", line 15, in myStringAPI self._prot.writeString(param) File "/home/jheimann/altair/thriftenv/local/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 123, in writeString self.trans.write(str) File "/home/jheimann/altair/thriftenv/local/lib/python2.7/site-packages/thrift/transport/TTransport.py", line 223, in write self._buffer.write(buf) UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) {code} > CLONE - why not add unicode strings support to python directly? > --------------------------------------------------------------- > > Key: THRIFT-3721 > URL: https://issues.apache.org/jira/browse/THRIFT-3721 > Project: Thrift > Issue Type: Bug > Components: Python - Library > Affects Versions: 0.8, 0.9.2 > Environment: Ubuntu 14.04.03 LTS, Ubuntu 15.10 > Reporter: Jason Heimann > Assignee: Jake Farrell > Labels: python, unicode > > i install thrift python lib by easy_install > but in version0.8,I still didn't see the > patch(https://issues.apache.org/jira/browse/THRIFT-395) be added in the lib > I had to hack the code follow the patch manually > (https://issues.apache.org/jira/secure/attachment/12404198/0003-THRIFT-395.-python-Phase-Two-of-support-for-unicode.patch) > Can any of the developers fix the problem? -- This message was sent by Atlassian JIRA (v6.3.4#6332)