SledgehammerPL SledgehammerPL - 6 months ago 39
Ajax Question

Sending UTF-encoded POST request


Possible Duplicate:

‘ascii’ codec can’t decode byte (problem when using django)


From a Chrome extension, I try to send a POST request:

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);


and when in
somevariable
, there are some UTF-chars, it breaks with


'ascii' codec can't decode byte 0xc4 in position 14: ordinal not in
range(128)


In Django I have:

some_var = form.cleaned_data['var'].replace('\n','')


The result is wrong because the
some_var
contains wrong chars:

some_var = u"blah blah blah z\u0142o\u017a"


Of course, it should be
u"blah blah blah złoź"
, but I really don't know where and how I should change the encoding.




Update after closure:

This question isn't duplicate - the problem isn't in the message. I googled more than you think you can.

The most important thing (which I don't understand) is the difference between

u"ł" and u"\u0142" and "\u0142"

all of those means almost the same, but not the same.

Answer

Should you be complaining about Unicode if you don't actually use it?

some_var = form.cleaned_data['var'].replace(u'\n', u'')
Comments