URLLIB请求无法处理中文字符

时间:2014-12-17 22:50:12

标签: python parsing python-3.x google-api urllib

我试图向api做一个curl请求,但中文字符发出错误

UnicodeEncodeError: 'ascii' codec can't encode characters in position 96-97: ordinal not in range(128)

与php不同,我可以简单地将角色抛入curl,但python似乎有所不同。知道我怎么能这样做吗?

以下是我使用的代码:

 query = urllib.parse.urlencode({'': '不存'})
        url = 'https://www.googleapis.com/language/translate/v2' + query
        print(url);
        search_response = urllib.request.urlopen(url)
        search_results = search_response.read().decode("utf8")
        results = json.loads(search_results)
        data = results['responseData']
        print(data);

0 个答案:

没有答案