LOGIN
How to urlencode a query string in Python?
P粉245489391
P粉245489391 2023-08-23 14:36:44
0
2
379

I'm trying to urlencode the string before submitting it.

queryString = 'eventName=' evt.fields["eventName"] '&' 'eventDescription=' evt.fields["eventDescription"];< /pre> 


P粉245489391
P粉245489391

reply all (2)
P粉270891688

Python 2

What you are looking for isurllib.quote_plus:

safe_string = urllib.quote_plus('string_of_characters_like_these:$#@=?%^Q^$') #Value: 'string_of_characters_like_these%3A%24%23%40%3D%3F%25%5EQ%5E%24'

Python 3

In Python 3, theurllibpackage has been broken into smaller components. You would useurllib.parse.quote_plus(note theparsesubmodule)

import urllib.parse safe_string = urllib.parse.quote_plus(...)
    P粉562845941

    You need to pass the parameters tourlencode()as a map (dict) or sequence of tuples, for example:

    >>> import urllib >>> f = { 'eventName' : 'myEvent', 'eventDescription' : 'cool event'} >>> urllib.urlencode(f) 'eventName=myEvent&eventDescription=cool+event'

    Python 3 or higher

    Usingurllib.parse.urlencode:

    >>> urllib.parse.urlencode(f) eventName=myEvent&eventDescription=cool+event

    Note that thisdoes notperform url encoding in the usual sense (see the output). To do this, useurllib.parse.quote_plus代码>.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!