def urlencode(query, doseq=0): """ A version of Python's urllib.urlencode() function that can operate on unicode strings. The parameters are first cast to UTF-8 encoded strings and then encoded as per normal. Based on the urlencode from django.utils.http """ if hasattr(query, 'items'): query = query.items() return original_urlencode( [(force_str(k), [force_str(i) for i in v] if isinstance(v, (list, tuple)) else force_str(v)) for k, v in query], doseq)
def urlencode(obj): utf8obj = dict((x.encode('utf-8'), y.encode('utf-8')) for x, y in obj.items()) return unicode(original_urlencode(utf8obj), 'utf-8')