Closed RuixiangS closed 1 year ago
Case: Add an additional question when I use emmett develop --interface asgi
I generate a new request whose headers["Api-key"]="not_foobar", otherwise condition will not work properly.
Expected: otherwise return {"error": "not authorized"}
Traceback (most recent call last):
File "D:\Anaconda\envs\emmett-frame\lib\asyncio\events.py", line 81, in _run
self._context.run(self._callback, *self._args)
File "D:\Anaconda\envs\emmett-frame\lib\site-packages\emmett\asgi\handlers.py", line 194, in __call__
await asyncio.wait_for(
File "D:\Anaconda\envs\emmett-frame\lib\asyncio\tasks.py", line 455, in wait_for
return await fut
File "D:\Anaconda\envs\emmett-frame\lib\site-packages\emmett\http.py", line 112, in asgi
await self._send_body(send)
File "D:\Anaconda\envs\emmett-frame\lib\site-packages\emmett\http.py", line 165, in _send_body
'body': self.encoded_body,
File "D:\Anaconda\envs\emmett-frame\lib\site-packages\emmett\http.py", line 160, in encoded_body
return self.body.encode('utf-8')
AttributeError: 'dict' object has no attribute 'encode'
Test
import requests
url = "http://localhost:8000/todo"
headers = {"Api-Key": "not_foobar"}
response = requests.get(url, headers=headers)
if response.status_code == 200:
tasks = response.json()["tasks"]
print(tasks)
else:
print("Error:", response.status_code, response.json())
My bad I didn't check the README example was still valid with 2.5
You can find the updated code in master
It seems like a granian bug, and it works when I use the
emmett develop --interface asgi
command that works out. system: Windows 10 Pro 22H2 19045.3086 my_package version list:example
My Test