Vũ Minh Vương
Vũ Minh Vương

Reputation: 163

Python encoding japanese characters

I'm using python for code send request to server(crawl data). But parameter is japanese. I'm using str.encode(encoding='utf-8') for parameter sent, method post

code request: response = requests.request(self.method, self.url,data=self.param.encode(encoding='Shift_JIS'), headers=headers)

but it's result is wrong base on info network of developer tool.

Example: right values:

In: 千代田区     Out:%90%E7%91%E3%93c%8B%E6

In: 東京都       Out: %93%8C%8B%9E%93s

If I use utf-8(wrong value):

In:東京都        Out: \x93\x8c\x8b\x9e\x93s

Can you please help me in this case!

Thanks all!

Upvotes: 1

Views: 5979

Answers (1)

Chathuranga
Chathuranga

Reputation: 1036

import urllib
value = { 'my_jap_stuff' : '千代田区' }
urllib.urlencode(value)

or python 3 <

import urllib.parse
value = { 'my_jap_stuff' : '千代田区' }
urllib.parse.urlencode(value)

Upvotes: 3

Related Questions