My application accepts data from POST method which I am running through JQuery's AJAX request. I am sending JSON formatted data, but in handler as I accept request and access the data it turns out to be byte string type.
I am using my_body = self.request.body
method.
For example, if I am sending {"drzava":"rs","kategorija":"general"}
received data looks like b'drzava=rs&kategorija=general'
.
Problem is, afterwards I can't use tornado.escape.json_decode()
, to make it dictionary. I keep getting the following error:
Traceback (most recent call last):
File "/home/stefan/.local/lib/python3.6/site-packages/tornado/web.py", line 1697, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "main.py", line 164, in post
telo_json = tornado.escape.json_decode(telo)
File "/home/stefan/.local/lib/python3.6/site-packages/tornado/escape.py", line 83, in json_decode
return json.loads(to_basestring(value))
File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I will post the code, if needed.