danieldaeschle / swapy

Easy and modular web development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected JsonMiddleware behaviour

opened this issue · comments


  • Bug
  • Feature
  • Question
  • Documentation issue

Error Log

 * Running on (Press CTRL+C to quit) - - [16/Feb/2018 22:46:38] "GET / HTTP/1.1" 200 - - - [16/Feb/2018 22:46:39] "GET /favicon.ico HTTP/1.1" 404 - - - [16/Feb/2018 22:46:53] "GET /every HTTP/1.1" 500 -
Error on request:
Traceback (most recent call last):
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\serving.py", line 270, in run_wsgi
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\serving.py", line 258, in execute
    application_iter = app(environ, start_response)
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\wsgi.py", line 48, in <lambda>
    return update_wrapper(lambda *a: f(*a)(*a[-2:]), f)
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\swapy\_utils.py", line 373, in application
    result = urls.dispatch(dispatch)
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\werkzeug\routing.py", line 1437, in dispatch
    return view_func(endpoint, args)
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\swapy\_utils.py", line 356, in dispatch
    res = response_from(f(req))
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\swapy\_utils.py", line 194, in handle
    res = target(**kwargs)
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\swapy\middlewares.py", line 45, in handle
    response = response_from(result)
  File "C:\Users\X\AppData\Local\Programs\Python\Python36\lib\site-packages\swapy\wrappers.py", line 16, in response_from
    return Response(*args)
TypeError: __init__() takes from 1 to 4 positional arguments but 5 were given

Current behavior


Expected behavior

Returning every registered URL as JSON Array.

How to reproduce the problem

def all_urls():
    return list(map(str, state('__main__').url_map.iter_rules()))

def every():
    return all_urls()

But what works:

def root():
    return {"all": all_urls()}


OS: Windows 10
Swapy version: 0.2.1
Python version: 3.6.3