cannot urllib.urlencode a URL in python

BillPull picture BillPull · Oct 14, 2011 · Viewed 44k times · Source

Why am I getting this error when trying to urlencode this string

 >>> callback = "http://localhost/application/authtwitter?twitterCallback"
 >>> urllib.urlencode(callback)
 Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.7/urllib.py", line 1261, in urlencode
      raise TypeError
 TypeError: not a valid non-string sequence or mapping object

Answer

retracile picture retracile · Oct 15, 2011

That's not what that function does:

urlencode(query, doseq=0)
    Encode a sequence of two-element tuples or dictionary into a URL query string.

Are you looking for urllib.quote(callback)?