8

Is there a way to urlencode/urldecode a string in Python? I want to emphasize that I want a single string, not a dict. I know of the function that does that to a dict. I could easily construct out of it a function that does that for a string, but I'd rather not have to construct my own function. Does Python have this functionality built-in?

(Answers for both Python 2.7 and 3.3 would be appreciated.)

3 Answers 3

5

See the urllib module (docs here), in particular the urllib.quote and urllib.unquote functions.

Sign up to request clarification or add additional context in comments.

Comments

2

urllib.unquote will do the trick

Comments

0

Use urllib.unquote and urllib.quote in Python

Example:

from urllib.parse import unquote
url='''search%20%60mic_conf-proxy-ui%60%20%22TEST--4b43d04c-1ba4-4d74-8596-25b68d255b3e%22'''
output=unquote(url)
print(output)
#search `mic_conf-proxy-ui` "TEST--4b43d04c-1ba4-4d74-8596-25b68d255b3e"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.