Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot urllib.urlencode a URL in python

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 
like image 609
BillPull Avatar asked Oct 14 '11 21:10

BillPull


People also ask

How do I encrypt a URL in Python?

You can encode multiple parameters at once using urllib. parse. urlencode() function. This is a convenience function which takes a dictionary of key value pairs or a sequence of two-element tuples and uses the quote_plus() function to encode every value.

How do you pass special characters in a URL in Python?

s = urllib2. quote(s) # URL encode. # Now "s" is encoded the way you need it. It works!

Does Python requests URL encode?

In Python, we can URL encode a query string using the urlib. parse module, which further contains a function urlencode() for encoding the query string in URL.

What does Urllib parse URL encode do?

parse. urlencode() method can be used for generating the query string of a URL or data for a POST request.


1 Answers

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) Python 2
  • urllib.parse.quote(callback) Python 3
like image 184
retracile Avatar answered Sep 18 '22 03:09

retracile