TypeError: Object of type 'NotFound' is not JSON serializable

0

I am mounting an ionic APP that makes request for an API in flask. The following error appeared when I try to make a post request:

  

TypeError: Object of type 'NotFound' is not JSON serializable

But when I test only the API doing request with files in python itself, it works without any problems.

Can anyone help me?

Patient provider code

patient.ts:

  public alterar_paciente(username_atual,nome,username,dataNascimento,sexo,email,celular,cidade,profissao,tipo,objetivo){
    var dados_paciente: any = {
      "username_atual": username_atual,
      "nome": nome,
      "username": username,
      "dataNascimento": dataNascimento,
      "sexo": sexo,
      "email": email,
      "celular": celular,
      "cidade": cidade,
      "profissao": profissao,
      "tipo": tipo,
      "objetivo": objetivo,
    }
    return this.http.post(this.base_path + "/paciente/alterar-paciente/", dados_paciente)
  } 

API code:

@app.route('/paciente/cadastrar', methods=["POST"])
def CadastrarPacienteRoute():
    from Nutrin.Paciente.Services.cadastrarPaciente import cadastrarPaciente
    dados = request.get_json()
    username = dados['username']
    password = dados['password']
    nome = dados['nome']
    email = dados['email']
    celular = dados['celular']
    dataNascimento = dados['dataNascimento']
    sexo = dados['sexo']
    cidade = dados['cidade']
    profissao = dados['profissao']
    objetivo = dados['objetivo']
    status, mensagem = cadastrarPaciente(username, password, nome, email, celular, dataNascimento, sexo, cidade, profissao, objetivo)
    if status:
        response["Status"] = "Sucesso"
        response["Dados"] = ""
        response["Mensagem"] = mensagem
        return jsonify(response)
    response["Status"] = "Erro"
    response["Dados"] = ""
    response["Mensagem"] = mensagem
    return jsonify(response)

Error:

Traceback (most recent call last):
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1997, in __call__
    return self.wsgi_app(environ, start_response)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1985, in wsgi_app
    response = self.handle_exception(e)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1540, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\_compat.py", line 33, in reraise
    raise value
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1982, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1512, in handle_user_exception
    return self.handle_http_exception(e)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\app.py", line 1471, in handle_http_exception
    return handler(e)
  File "C:\Users\mplus\Documents\GitHub\API-Nutrin\Nutrin\Paciente\ErrorHandlers.py", line 16, in Error404
    return jsonify(response)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\json.py", line 263, in jsonify
    (dumps(data, indent=indent, separators=separators), '\n'),
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\json.py", line 123, in dumps
    rv = _json.dumps(obj, **kwargs)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 201, in encode
    chunks = list(chunks)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 430, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 404, in _iterencode_dict
    yield from chunks
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 437, in _iterencode
    o = _default(o)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\flask\json.py", line 80, in default
    return _json.JSONEncoder.default(self, o)
  File "C:\Users\mplus\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 180, in default
    o.__class__.__name__)
TypeError: Object of type 'NotFound' is not JSON serializable
    
asked by anonymous 26.08.2018 / 00:04

0 answers