I have this webservice, based on the Pyramid framework, that accepts a multipart/form-data request.
Everything works when I send the request from cURL; however from the Android application, it fails with the following error
TypeError: must be str, not bytes
when I try to access any field : e.g. request.POST.get('smartphoneId', None)
The difference is that the Android library adds a few headers to the fields, notably the Content-Transfer-Encoding. From cURL each value is sent as follows :
--------------------------5f28b737bc4e4813
Content-Disposition: form-data; name="smartphoneId"
2
whereas from Android (with retrofit) :
--0e0a43aa-3156-48ee-a949-931dcc4eb8be
Content-Disposition: form-data; name="smartphoneId"
Content-Type: text/plain; charset=UTF-8
Content-Length: 3
Content-Transfer-Encoding: 8BIT
999
Initially the Content-Transfer-Encoding was binary ; I manually changed it to 8BIT, but I get the same error. Seems that Python can't parse / handle the content of each field.
Any idea ?
str()
or revert to Python 2 if the library is not yet Py3k-compatible. – tripleeedecode
() method. – cdarke