简体   繁体   中英

how to read japanese characters from request?

I have the below url which is already encoded to pass japanese characters into browser's URL address bar.

http://localhost:8000/service/social/acc?auth=true&body=%7B%22site%22%3A%22twitter%22%2C%22account%22%3A%
22twitter_1%22%2C%22name%22%3A%22%93X%95%DC1%22%7D

I can get the value from request but it is garbled or garbage text.

Is there any special things need to do to be able to read japanese characters from request object?

I try this. '店舗' means 'shop' in Japanese.

>In [1]: from urlparse import *
>
>In [2]: url = urlparse('http://localhost:8000/service/social/acc?auth=true&body=%7B%22site%22%3A%22twitter%22%2C%22account%22%3A%22twitter_1%22%2C%22name%22%3A%22%93X%95%DC1%22%7D')
>
>In [3]: url
>Out[3]: ParseResult(scheme='http', netloc='localhost:8000', path='/service/social/acc', params='', query='auth=true&body=%7B%22site%22%3A%22twitter%22%2C%22account%22%3A%22twitter_1%22%2C%22name%22%3A%22%93X%95%DC1%22%7D', fragment='')
>
>In [4]: parse_qs(url.query)
>Out[4]:
{'auth': ['true'],
 'body': ['{"site":"twitter","account":"twitter_1","name":"\x93X\x95\xdc1"}']}
>
>In [5]: name = "\x93X\x95\xdc1"
>
>In [5]: print name.decode('shift-jis')
>
>店舗1

You need to encode the data first...lets say in utf-8. Then add this data to the url. Then on the server side get the data from the url and then decode it back.

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM