The problem: I am using Daphne with Django 4.0. I have created a functional view using async,
async def inputView(request):
print("Guess where I am")
return HttpResponse("Well, I recieved the file.")
and I am sending a POST request with a file using CURL to this view and just returning an HTTPResponse but still it is giving this error:
2022-04-01 06:05:29,969 INFO Starting server at tcp:port=8000:interface=127.0.0.1
2022-04-01 06:05:29,970 INFO HTTP/2 support enabled
2022-04-01 06:05:29,970 INFO Configuring endpoint tcp:port=8000:interface=127.0.0.1
2022-04-01 06:05:29,970 INFO Listening on TCP address 127.0.0.1:8000
Internal Server Error: /primerDesign/uploadInput
Traceback (most recent call last):
File â/home/biord002/im-lab/lib/python3.8/site-packages/asgiref/sync.pyâ, line 451, in thread_handler
raise exc_info[1]
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/exception.pyâ, line 38, in inner
response = await get_response(request)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 243, in _get_response_async
self.check_response(response, callback)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 314, in check_response
raise ValueError(
ValueError: The view primerDesign.views.inputView didnât return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an âawaitâ into your view.
2022-04-01 06:05:34,930 ERROR Internal Server Error: /primerDesign/uploadInput
Traceback (most recent call last):
File â/home/biord002/im-lab/lib/python3.8/site-packages/asgiref/sync.pyâ, line 451, in thread_handler
raise exc_info[1]
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/exception.pyâ, line 38, in inner
response = await get_response(request)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 243, in _get_response_async
self.check_response(response, callback)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 314, in check_response
raise ValueError(
ValueError: The view primerDesign.views.inputView didnât return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an âawaitâ into your view.
127.0.0.1:34482 - - [01/Apr/2022:06:05:34] âPOST /primerDesign/uploadInputâ 500 59356
127.0.0.1:34484 - - [01/Apr/2022:06:06:25] âGET /primerDesign/â 200 47
Internal Server Error: /primerDesign/uploadInput
Traceback (most recent call last):
File â/home/biord002/im-lab/lib/python3.8/site-packages/asgiref/sync.pyâ, line 451, in thread_handler
raise exc_info[1]
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/exception.pyâ, line 38, in inner
response = await get_response(request)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 243, in _get_response_async
self.check_response(response, callback)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 314, in check_response
raise ValueError(
ValueError: The view primerDesign.views.inputView didnât return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an âawaitâ into your view.
2022-04-01 06:06:49,191 ERROR Internal Server Error: /primerDesign/uploadInput
Traceback (most recent call last):
File â/home/biord002/im-lab/lib/python3.8/site-packages/asgiref/sync.pyâ, line 451, in thread_handler
raise exc_info[1]
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/exception.pyâ, line 38, in inner
response = await get_response(request)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 243, in _get_response_async
self.check_response(response, callback)
File â/home/biord002/im-lab/lib/python3.8/site-packages/django/core/handlers/base.pyâ, line 314, in check_response
raise ValueError(
ValueError: The view primerDesign.views.inputView didnât return an HttpResponse object. It returned an unawaited coroutine instead. You may need to add an âawaitâ into your view.
127.0.0.1:34488 - - [01/Apr/2022:06:06:49] âPOST /primerDesign/uploadInputâ 500 59356
The curl request is this:
time curl -v -X POST -F âFILE=@/home/biord002/file.txtâ http://127.0.0.1:8000/primerDesign/uploadInput
I have another view, index, with same structure but I am sending a GET request and that view works just fine.
My urls.py:
urlpatterns = [
path("", index),
path("uploadInput", csrf_exempt(inputView)),
]
index view:
async def index(request):
return HttpResponse("hello bruh, I am done.")
Thanks in advance.