Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode a string for url param in python [duplicate]

How can I encode a string so that I can pass the encoded string in url params?

like image 879
rpdev123 Avatar asked Feb 14 '23 05:02

rpdev123


1 Answers

use urllib.quote_plus function. Here is an example:

#!/usr/bin/python

print "Content-Type: text/html;charset=utf-8";
print

import urllib

str = "Hello World?"
str = urllib.quote_plus(str)

print str

Output: Hello+World%3F

like image 193
Mosiur Avatar answered Feb 20 '23 11:02

Mosiur