How to URL encode in Python 3?

前端 未结 3 983
夕颜
夕颜 2020-12-13 12:32

I have tried to follow the documentation but was not able to use urlparse.parse.quote_plus() in Python 3:

from urllib.parse import          


        
3条回答
  •  情书的邮戳
    2020-12-13 12:35

    You’re looking for urllib.parse.urlencode

    import urllib.parse
    
    params = {'username': 'administrator', 'password': 'xyz'}
    encoded = urllib.parse.urlencode(params)
    # Returns: 'username=administrator&password=xyz'
    

提交回复
热议问题