i am gettin an error "[Errno 5] Input/output error" while running an api on django
Asked Answered
G

2

6

Django API Code:

def post(self,request)-> JsonResponse:
        try:
            self.email = request.data['email']
            self.mobile = request.data['mobile']
            self.password = request.data['password']
        except Exception as e:
            return JsonResponse(create_failure('400',f"invalid payload {e}","fail"))
        try:
            res = {}
            jwt_token = ''
            if self.email:
                password = Customer.objects.get(email=self.email).password
                username  = Customer.objects.get(email=self.email).username
                print(password)
                if check_password(self.password,password) :
                    jwt_token = make_jwt_token({'username':username})
                else:
                    return JsonResponse(create_failure('500',f"Invalid password","fail"))
            elif self.mobile:
                password = Customer.objects.get(mobile=self.mobile).password
                username  = Customer.objects.get(mobile=self.mobile).username
                if check_password( password,self.password) :
                    jwt_token = make_jwt_token({'username':username})
                else:
                    return JsonResponse(create_failure('500',f"Invalid password","fail"))
            res['token'] = jwt_token
        except Exception as e:
            return JsonResponse(create_failure('400',f"error in verifying the password {e}","fail"))
        return JsonResponse(create_success('User Verified',res))

Error while running it on the postman

{
    "StatusCode": "400",
    "Message": "error in verifying the password [Errno 5] Input/output error",
    "ReplyCode": "fail",
    "Data": []
}

Above code is working fine on the local machine, but it creates this error when I deploy it to the server. I am using cpanel for the hosting which uses CentOS

Geis answered 29/6, 2021 at 5:54 Comment(2)
Have you run out of disk space on your server?Abolition
NO there is plenty of space on the server.Geis
G
9

Resolved I just had to remove the print from the code.

Geis answered 29/6, 2021 at 6:40 Comment(0)
E
11

This might happen if your server has nowhere to put the print statements.

For example, I was running a server in one terminal window, then somehow the window got closed but the server was still running. There are 2 options, depending on your situation:

  1. Kill the process. Start a new server: sudo kill -9 $(sudo lsof -t -i:8000). (or search "find port and kill process [YOUR_OS]" to find OS-specific information. More details

  2. Pipe your command output: python MY_SCRIPT.py >/dev/null More details

Emit answered 13/4, 2022 at 11:10 Comment(0)
G
9

Resolved I just had to remove the print from the code.

Geis answered 29/6, 2021 at 6:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.