Categories
Python Answers

How to urlencode a querystring in Python?

Spread the love

Sometimes, we want to urlencode a querystring in Python.

In this article, we’ll look at how to urlencode a querystring in Python.

How to urlencode a querystring in Python?

To urlencode a querystring in Python, we can use the urllib.parse.quote_plus method.

For instance, we wite

import urllib.parse

safe_string = urllib.parse.quote_plus('string_of_characters_like_these:$#@=?%^Q^$')

to call quote_plus with a string that we want to urlencode.

Conclusion

To urlencode a querystring in Python, we can use the urllib.parse.quote_plus method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *