我编写了PUT请求API来设置用户密码。我写了这么多的意见,但我没有遇到任何问题,如在下面的视图功能
views.py
@api_view(['PUT'])
@permission_classes([])
def setForgotPasswordWithNewPassword(request):
data = request.data
print(data)
user = User.objects.get(username=data['username'])
secret_key = request.data['secretkey']
backend_secretkey = cache.get('reset_pwd_%s' % (data['username']))
if backend_secretkey:
if backend_secretkey == secret_key:
if user:
user.set_password(data['password'])
# print(user.password)
user.save()
return Response({"msg":"Your password has been successfully changed"},status=200)
else:
return Response({"error":"Username does not exist on our system"},status=403)
else:
return Response({"error": "Your not authorized to use this link"}, status=403)
else:
return Response({"error": "Your password link has been expired, please try again"}, status=403)
使用Postman,我在命令行上没有得到任何异常。但是当我使用Angular项目点击这个API时,得到了下面的异常,并且由于这个异常,wsgi服务器再次加载,所以Angular再次加载到首页。但更改密码是可行的。所以我很想知道我正在经历的这个错误
错误:
[15/Jun/2020 00:34:01] "PUT /api/setForgotPasswordWithNewPwd/ HTTP/1.1" 200 53
Traceback (most recent call last):
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write
self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
[15/Jun/2020 00:34:01] "PUT /api/setForgotPasswordWithNewPwd/ HTTP/1.1" 500 59
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 49954)
Traceback (most recent call last):
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 138, in run
self.finish_response()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 332, in send_headers
self.send_preamble()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 255, in send_preamble
('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 453, in _write
result = self.stdout.write(data)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 803, in write
self._sock.sendall(b)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 141, in run
self.handle_error()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 119, in handle_error
super().handle_error()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 368, in handle_error
self.finish_response()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 180, in finish_response
self.write(data)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 274, in write
self.send_headers()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 331, in send_headers
if not self.origin_server or self.client_is_modern():
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 344, in client_is_modern
return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
TypeError: 'NoneType' object is not subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 654, in process_request_thread
self.finish_request(request, client_address)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 364, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\socketserver.py", line 724, in __init__
self.handle()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 174, in handle
self.handle_one_request()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 197, in handle_one_request
handler.run(self.server.get_app())
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\handlers.py", line 144, in run
self.close()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\servers\basehttp.py", line 114, in close
super().close()
File "C:\Users\vipin\AppData\Local\Programs\Python\Python36\lib\wsgiref\simple_server.py", line 35, in close
self.status.split(' ',1)[0], self.bytes_sent
AttributeError: 'NoneType' object has no attribute 'split'
使用邮递员工具调用不会得到任何类似上述的异常
我的天使般的呼唤:
setForgotPassword(data):Observable<any>{
return this.http.put<any>(this._base_url+this._setForgotPassword_url,data)
}
打字稿:
setPassword(secretkey){
this.data.secretkey = secretkey
console.log(this.data)
this.usr_srv.setForgotPassword(this.data).subscribe(
res => {
console.log(res)
// let dialogRef = this.dialog.open(DialogDataExampleDialog,{
// data: {msg: 'Your password has been successfully set',color:"green"}
// });
// dialogRef.afterClosed().subscribe(result => {
// this._router.navigate(['/login'])
// });
},
err =>{
console.log(err)
// let dialogRef = this.dialog.open(DialogDataExampleDialog,{
// data: {msg: err.error.error,color:"red"}
// });
// dialogRef.afterClosed().subscribe(result => {
// this._router.navigate(['/login'])
// });
}
)
}
目前没有回答
相关问题 更多 >
编程相关推荐