A_Matar
A_Matar

Reputation: 2330

Python string encoding: An extra backslash added to strings when sent over http

When I post a string "\u062c\u0646\u062f\u064a\u0651\u0627" via an HTTP request it is received as the following '\\u062c\\u0646\\u062f\\u064a\\u0651\\u0627'. What are the extra backslashes added for? And how to strip them?

Upvotes: 1

Views: 226

Answers (1)

JosefZ
JosefZ

Reputation: 30218

… how to strip them?

s_sent     = "\u062c\u0646\u062f\u064a\u0651\u0627"
s_received = '\\u062c\\u0646\\u062f\\u064a\\u0651\\u0627'
s_sent == s_received.encode().decode('unicode-escape')
True

Upvotes: 1

Related Questions