Ho un problema su urlencode in python 2.7:Perché non riesco a utilizzare urlencode per codificare i dati in formato json?
>>> import urllib
>>> import json
>>> urllib.urlencode(json.dumps({'title':"hello world!",'anonymous':False,'needautocategory':True}))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/urllib.py", line 1280, in urlencode
raise TypeError
TypeError: not a valid non-string sequence or mapping object
Nota che 'quote_plus()' trasformerà i tuoi spazi in '+'. Quando si ha a che fare con JSON si potrebbe desiderare di mantenerli come '% 20', usare' quote() 'per quello – neric