Skip to main content
 首页 » 编程设计

python之Django : An established connection was aborted by the software in your host machine

2025年05月04日118zdz8207

当我在发布请求中添加特定行时出现此错误。

View .py

class LoginVerify(View): 
    print('login') 
    email ="" 
    pswd = "" 
    username ="" 
 
    def post(self,request,*args,**kwargs): 
        print("post called") 
        self.email = request.POST['email'] 
        self.pswd = request.POST['pswd'] 
        self.username = User.objects.get(email=self.email).username 
        return HttpResponse("Invalid user") 

如果我添加 self.username = User.objects.get(email=self.email).username 然后它显示错误,否则它工作正常。

为什么会这样,我该如何解决?

请您参考如下方法:

我通常在我的本地机器上以 Debug模式运行时得到这个通常发生在服务器响应请求并且客户端已经关闭连接的情况下。您可以忽略该错误或使用不同的生产服务器,例如具有更好服务器套接字处理能力的 gunicorn。仅供引用,我在 python 2.7 上看到这个错误