How to urlencode a querystring in Python?

后端 未结 13 1912
猫巷女王i
猫巷女王i 2020-11-22 11:19

I am trying to urlencode this string before I submit.

queryString = \'eventName=\' + evt.fields[\"eventName\"] + \'&\' + \'eventDescription=\' + evt.fie         


        
13条回答
  •  春和景丽
    2020-11-22 11:50

    Python 2

    What you're looking for is urllib.quote_plus:

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

    Python 3

    In Python 3, the urllib package has been broken into smaller components. You'll use urllib.parse.quote_plus (note the parse child module)

    import urllib.parse
    urllib.parse.quote_plus(...)
    

提交回复
热议问题