0

if I escape '가온' in javascript,

the result would be:

escape('가온')
'%uAC00%uC628'

I want to get the same result like the js in python.

However, if I encode as ascii like:

byte_string= "누리".encode('ascii', 'backslashreplace')
b'\\ub204\\ub9ac'

the result isn't same. How can I?

shim robin
  • 37
  • 5

2 Answers2

0

Something is confusing in your question: first you encode '가온' then '누리'.

I think encoding with 'backslashreplace' can work as long as you decode and replace the backslashes with %:

"가온".encode('ascii', 'backslashreplace').decode().replace('\\', '%')

Output:

%uac00%uc628
Tranbi
  • 11,407
  • 6
  • 16
  • 33
0

JavaScript escape() is URL escape.

You can get this using urllib in Python.

Note that URLs may have multiple different encodings for the same characters. However any valid URL parses should accept any encoding.

Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435