Python编码似乎不正确

问题描述 投票:1回答:2
from jsonrpclib import jsonrpc

url = 'https://myserver.com:443'
jpc = jsonrpc.Server('%s/jsonrpc' % url)
new_string = "金衣大俠"
jpc.editqueue("NewName", new_string, 123)

new_string在我的服务器中显示为Ñc'à。服务器支持外来字符,如果我复制new_string中的文本,则可以通过UI(不使用jsonrpc)将其粘贴并保存在服务器中,并且看起来很好。我想我必须以某种方式编码我的字符串才能工作。关于如何编码字符串以使其工作的任何想法?

python python-3.x encoding rpc
2个回答
0
投票

Python编码已经在其他堆栈交换中得到了解答。请引用链接here,并在第5行上适当定义new_string


0
投票

请澄清:

以某种方式编码我的字符串*]

您可以使用内置字符串encode / decode函数。

new_string = u'金衣大俠' #force it to unicode

# On the client side:
encoded_string = new_string.encode('utf-16')

# and on the server side:
decoded_string = received_string.decode('utf-16')
© www.soinside.com 2019 - 2024. All rights reserved.