Skip to content

Instantly share code, notes, and snippets.

@eloff
Created September 27, 2011 22:33
Show Gist options
  • Save eloff/1246455 to your computer and use it in GitHub Desktop.
Save eloff/1246455 to your computer and use it in GitHub Desktop.
Add query params to url
from urlparse import urlparse, urlunparse
from urllib import urlencode
def add_query_args(uri, **params):
parts = list(urlparse(uri))
qs = urlencode(params)
if parts[4]:
parts[4] += '&' + qs
else:
parts[4] = qs
return urlunparse(parts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment