KoalaTea / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

Chinese character support #78

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
[Use this form for both apiclient and oauth2client issues]

What steps will reproduce the problem?
#/usr/bin/python main.py
Traceback (most recent call last):
  File "main.py", line 42, in <module>
    main()
  File "main.py", line 38, in main
    q=['由“基督']
  File "/Library/Python/2.6/site-packages/google_api_python_client-1.0beta7-py2.6.egg/apiclient/discovery.py", line 454, in method
    actual_path_params, actual_query_params, body_value)
  File "/Library/Python/2.6/site-packages/google_api_python_client-1.0beta7-py2.6.egg/apiclient/model.py", line 140, in request
    query = self._build_query(query_params)
  File "/Library/Python/2.6/site-packages/google_api_python_client-1.0beta7-py2.6.egg/apiclient/model.py", line 170, in _build_query
    x = x.encode('utf-8')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal 
not in range(128)

What is the expected output? What do you see instead?
Expected English translation of Chinese characters.

What version of the product are you using? On what operating system?
Mac OS X 10.6 and python 2.6.1

Please provide any additional information below.
Googled extensively to locate code to attempt to modify model.py to encode 
utf-8, but I am fairly new to python, and probably barking up the wrong tree.

Original issue reported on code.google.com by michael....@chinamonitorinc.com on 2 Jan 2012 at 3:58

GoogleCodeExporter commented 8 years ago
Using google-api-python-client-1.0beta7.tar.gz

Original comment by michael....@chinamonitorinc.com on 2 Jan 2012 at 5:27

GoogleCodeExporter commented 8 years ago
Chinese characters must be supplied in unicode strings:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> q=['由“基督']
>>> q[0].encode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe7 in position 0: ordinal 
not in range(128)

>>> q=[u'由“基督']
>>> q[0].encode('utf-8')
'\xe7\x94\xb1\xe2\x80\x9c\xe5\x9f\xba\xe7\x9d\xa3'
>>> 

Original comment by jcgregorio@google.com on 2 Jan 2012 at 5:29

GoogleCodeExporter commented 8 years ago
Thank you so much!!! Just add the 'u' and it works like a charm! Thanks again!!

Original comment by michael....@chinamonitorinc.com on 2 Jan 2012 at 5:39