I have some code to encrypt some strings in Python. Encrypted text is used as a parameter in some urls, but after encrypting, there comes backslashes in string and I cannot use single backslash in urllib2.urlopen.
I cannot replace single backslash with double. For example:
print cipherText
'\t3-@\xab7+\xc7\x93H\xdc\xd1\x13G\xe1\xfb'
print cipherText.replace('\\','\\\\')
'\t3-@\xab7+\xc7\x93H\xdc\xd1\x13G\xe1\xfb'
Also putting r in front of \ in replace statement did not worked.
All I want to do is calling that kind of url:
http://awebsite.me/main?param="\t3-@\xab7+\xc7\x93H\xdc\xd1\x13G\xe1\xfb"
An开发者_如何学编程d also this url can be successfully called:
http://awebsite.me/main?param="\\t3-@\\xab7+\\xc7\\x93H\\xdc\\xd1\\x13G\\xe1\\xfb"
probably what you are seeing is not a real "backslash character", but it is the string representation of a non printable (or non-ascii) character. For example \t
is Tab, not a backslash and t
.
You should build your url with
"http://awebsite.me/main?%s" % (urllib.urlencode({'param': cipherText}))
精彩评论