Similar Issue:
‘ascii’ codec can’t decode byte (problem when using django)
Attempting to send a POST request from a Chrome extension:
var = encodeURIComponent(somevariable);
var parameters = "var=" + var;
mypostrequest.open("POST", "django/page/", true);
mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
mypostrequest.send(parameters);
However, if there are UTF-chars in somevariable
, it throws an error:
'ascii' codec can't decode byte 0xc4 in position 14: ordinal not in range(128)
In my Django code:
some_var = form.cleaned_data['var'].replace('\n','')
The issue is that some_var
contains incorrect characters:
some_var = u"blah blah blah z\u0142o\u017a"
It should actually be u"blah blah blah złoź"
, but I am unsure how to fix the encoding problem.
Update after further examination:
This question is unique - the underlying problem is deeper than what was previously suggested. Extensive research has been conducted into this matter.
The key point of confusion lies in the difference between
u"ł" and u"\u0142" and "\u0142"
each representing something similar, yet subtly distinct.