kytos / flow_manager

MIT License
1 stars 16 forks source link

JSON serialization error when listing flows through REST API (OF1.0) #97

Closed hdiogenes closed 3 years ago

hdiogenes commented 3 years ago

Documenting the issue originally reported by @josemauro and @cmagnobarbosa:

2020-11-26 18:41:18,413 - ERROR [kytos.core.controller] (Thread-933) Exception on /api/kytos/flow_manager/v2/flows [GET]
Traceback (most recent call last):
  File "venv/lib/python3.8/site-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "venv/lib/python3.8/site-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "venv/lib/python3.8/site-packages/flask_cors/extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "venv/lib/python3.8/site-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "venv/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "venv/lib/python3.8/site-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "venv/lib/python3.8/site-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "venv/var/lib/kytos/napps/kytos/flow_manager/main.py", line 167, in list
    flows_dict = [flow.as_dict() for flow in switch.flows]
  File "venv/var/lib/kytos/napps/kytos/flow_manager/main.py", line 167, in <listcomp>
    flows_dict = [flow.as_dict() for flow in switch.flows]
  File "venv/var/lib/kytos/napps/../napps/kytos/of_core/flow.py", line 122, in as_dict
    flow_dict['id'] = self.id
  File "venv/var/lib/kytos/napps/../napps/kytos/of_core/flow.py", line 94, in id
    flow_str = self.as_json(sort_keys=True, include_id=False)
  File "venv/var/lib/kytos/napps/../napps/kytos/of_core/flow.py", line 167, in as_json
    return json.dumps(self.as_dict(include_id), sort_keys=sort_keys)
  File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
    return cls(
  File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.8/json/encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type UBInt16 is not JSON serializable