Use first_or_404() method of sqlalchemy and catch socket error in User.post()