How to urlencode a query string in Python?
P粉245489391
2023-08-23 14:36:44
<p>I'm trying to urlencode the string before submitting it. </p>
<pre class="brush:php;toolbar:false;">queryString = 'eventName=' evt.fields["eventName"] '&' 'eventDescription=' evt.fields["eventDescription"];< /pre>
<p><br /></p>
Python 2
What you are looking for is
urllib.quote_plus
:Python 3
In Python 3, the
urllib
package has been broken into smaller components. You would useurllib.parse.quote_plus
(note theparse
submodule)You need to pass the parameters to
urlencode()
as a map (dict) or sequence of tuples, for example:Python 3 or higher
Using
urllib.parse.urlencode
:Note that this does not perform url encoding in the usual sense (see the output). To do this, use
urllib.parse.quote_plus代码>
.