Why Python requests library failing to get response?

安稳与你 提交于 2019-12-01 23:51:40

I believe this is because you are using the Django runserver (correct me if I am wrong) which is not multi-threaded

https://code.djangoproject.com/ticket/3357

So you request to localhost:8000 is queued waiting for the request that made the request to finish! Not ideal.

In production, where you are running your server with a wsgi app (like uwsgi) this would be OK because it is multithreaded.

The reason it works in this test case is because you are making the request from the test thread to the test server that is being run in a different thread.

EDIT #1: A few things to think about

1) Why are your accepting your registration form in a GET request and not a POST request? This is an abuse of the GET verb because you are actually creating something on the server

2) Why are you calling your own API from inside your application and not putting this functionality into a method that can be called from all endpoints that need it?

EDIT #2:

As stated in the comments, the dev server is multithreaded

https://github.com/django/django/commit/ce165f7bbf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!