-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
invalidThis doesn't seem rightThis doesn't seem rightoutdatedquestionStackOverflowStackOverflowserverwontfix
Description
Long story short
The following code:
arguments = await request.json()
print(arguments)
Raises an exception:
[2018-09-29 11:42:33 +0000] [93] [ERROR] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 390, in start
resp = await self._request_handler(request)
File "/usr/local/lib/python3.6/site-packages/aiohttp/web_app.py", line 366, in _handle
resp = await handler(request)
File "/usr/local/lib/python3.6/site-packages/aiohttp/web_middlewares.py", line 106, in impl
return await handler(request)
File "/project/main/rest/middlewares/authorization.py", line 39, in auth_token_validation_middleware
return await handler(request)
File "/usr/local/lib/python3.6/site-packages/aiohttp/web_urldispatcher.py", line 740, in _iter
resp = await method()
File "/project/main/rest/endpoints/service/services/authentication/single.py", line 26, in put
return await authentication.create_token(request=self.request)
File "/project/main/core/service/services/authentication.py", line 99, in create_token
arguments = await request.json()
File "/usr/local/lib/python3.6/site-packages/aiohttp/web_request.py", line 551, in json
return loads(body)
File "/usr/local/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/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)
After my http request without (!) PUT
parameters:
http PUT :8000/some/endpoint
Expected behaviour
I expect, if length of request.text()
equals 0, request.json()
will return empty dictionary {}
instead of raising.
Actual behaviour
While I pass parameter, my request.text()
equals {"key": "value"}
and request.json()
equals {'key': 'value'}
. When I do not pass parameter, JSONDecodeError
is raised.
Steps to reproduce
from aiohttp import web
class SomeView(web.View):
async def put(self):
arguments = self.request.json()
...
Your environment
- aiohttp (3.4.2)
- Python 3.6
- MacOs
- Server
Metadata
Metadata
Assignees
Labels
invalidThis doesn't seem rightThis doesn't seem rightoutdatedquestionStackOverflowStackOverflowserverwontfix