I am loading some data into a django view. Customer:
from poster.encode import multipart_encode def upload_data(upload_url, data, filename): print "Uploading %d bytes to server, file=%s..." % (len(data), filename) datagen, headers = multipart_encode({filename: data}) request = urllib2.Request(upload_url, datagen, headers)
View:
def my_view(request): event_dicts_td_json_gz = request.POST.get('event_dicts_td.json.gz') if not event_dicts_td_json_gz: return HttpResponse("fail") print type(event_dicts_td_json_gz), repr(event_dicts_td_json_gz[:10]) event_dicts_td_json_gz = event_dicts_td_json_gz.encode("utf8") print type(event_dicts_td_json_gz), repr(event_dicts_td_json_gz[:10]) event_dicts_td_json = event_dicts_td_json_gz.decode("zlib").decode("utf8") return HttpResponse("it still failed")
Output:
<type 'unicode'> u'x\ufffd\ufffd]s\ufffd\u0192\ufffd\ufffd\n' <type 'str'> 'x\xef\xbf\xbd\xef\xbf\xbd]s\xef'
This is unacceptable. I just need raw bytes. I do not load unicode - I load raw bytes - and I want to return these raw bytes. I donβt know how he is trying to decode it in unicode - apparently not using utf8 , because zlib could not decompress the data. (He could not unpack it, even when I did not try to execute .encode("utf8") before zlibbing-it, it was just a test.)
How to make django not unify POST variables? Or, if so, how can I cancel it?
source share