danieldaeschle / swapy

Easy and modular web development

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected JsonMiddleware behaviour

opened this issue · comments

Submitting...

  • Bug
  • Feature
  • Question
  • Documentation issue

Error Log

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [16/Feb/2018 22:46:38] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [16/Feb/2018 22:46:39] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [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
    execute(self.server.app)
  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

Error?

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()))

@swapy.on("/every")
@JsonMiddleware
def every():
    return all_urls()

But what works:

@swapy.on()
@JsonMiddleware
def root():
    return {"all": all_urls()}

Environment

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