How to urlencode a querystring in Python?

后端 未结 13 2009
猫巷女王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:38

    For use in scripts/programs which need to support both python 2 and 3, the six module provides quote and urlencode functions:

    >>> from six.moves.urllib.parse import urlencode, quote
    >>> data = {'some': 'query', 'for': 'encoding'}
    >>> urlencode(data)
    'some=query&for=encoding'
    >>> url = '/some/url/with spaces and %;!<>&'
    >>> quote(url)
    '/some/url/with%20spaces%20and%20%25%3B%21%3C%3E%26'
    

提交回复
热议问题