Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError exception in response validation with falcon framework #138

Open
marco-a-itl opened this issue Feb 14, 2019 · 0 comments
Open

Comments

@marco-a-itl
Copy link

Running code generated for falcon framework from the following yaml file

https://forge.etsi.org/gitlab/mec/gs011-app-enablement-api/blob/master/Mp1.yaml

I get an exception for every response that the application tries to send out:

[2019-02-14 09:36:04 +0000] [17948] [ERROR] Error handling request /exampleAPI/mp1/v1/applications/applicazione1/dns_rules
Traceback (most recent call last):
  File "/src/var/mec/prova_venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 135, in handle
    self.handle_request(listener, req, client, addr)
  File "/src/var/mec/prova_venv/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 176, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/src/var/mec/prova_venv/lib/python2.7/site-packages/falcon/api.py", line 244, in __call__
    responder(req, resp, **params)
  File "/src/var/mec/prova_venv/lib/python2.7/site-packages/falcon/hooks.py", line 182, in do_after
    shim(req, resp, self, *action_args, **action_kwargs)
  File "/src/var/mec/swagger_test/mp1_ref/mp1_ref/exampleAPI_mp1_v1/validators.py", line 169, in response_filter
    description='`%d` is not a defined status code.' % status)
TypeError: %d format: a number is required, not NoneType

This is due to the fact that in validators.py (function response_filter) the status variable is (in falcon) a string containing the status code and the reason phrase, while filter is a dictionary indexed by status code as integer.

My workaround is the following:

-    status = None
-
-    if len(filter) == 1:
-        if six.PY3:
-            status = list(filter.keys())[0]
-        else:
-            status = filter.keys()[0]
+    status = int(resp.status.split()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant