Python: Remove querystring from URL

Needed to clean an URL from it’s querystring in Python. Found a lot of examples telling me to use urlparse and then put all the bits and pieces back together. An easier and more efficient  way is this:
[py]url = ‘’
url = url[:url.find(‘?’)][/py]
url now reads’

3 Comments on “Python: Remove querystring from URL”

  1. Thanks for sharing it!

    But it doesn’t work if the uri has no query string.

    I’m using this:

    uri = uri.rsplit(‘?’, 1)[0]


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: