从Urllib2请求的Unicode

2024-05-23 17:48:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用urllib2发送post请求,因此部分结果包含 Unicode示例:\u10dc\u10d0\u10d7\u10d8\u10d0

所以我想让我的代码解码这段文字,有什么想法吗

我试过这个text=“\u10dc\u10d0\u10d7\u10d8\u10d0” text.decode('utf-8')但它不起作用

我的代码如下所示:

request = urllib2.Request(url, data=data, headers=request_headers)
request.get_method = lambda: method
connection = opener.open(request)
data = connection.read()
print data

Tags: 代码text示例datarequestunicodeurllib2connection