Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: __init__() got an unexpected keyword argument 'as_tuple'

While I am testing my API I recently started to get the error below.

        if request is None:
>           builder = EnvironBuilder(*args, **kwargs)
E           TypeError: __init__() got an unexpected keyword argument 'as_tuple'

/usr/local/lib/python3.7/site-packages/werkzeug/test.py:1081: TypeError

As I read from the documentation in the newer version of Werkzeug the as_tuple parameter is removed.

Part of my test code is


from flask.testing import FlaskClient

@pytest.fixture(name='test_client')
def _test_client() -> FlaskClient:
    app = create_app()
    return app.test_client()


class TestPeerscoutAPI:
    def test_should_have_access_for_status_page(self, test_client: FlaskClient):
        response = test_client.get('/api/status')
        assert _get_ok_json(response) == {"status": "OK"}

Any help would be greatly appreciated.

like image 704
hazalciplak Avatar asked Aug 31 '25 16:08

hazalciplak


2 Answers

As of version 2.1.0, werkzeug has removed the as_tuple argument to Client. Since Flask wraps werkzeug and you're using a version that still passes this argument, it will fail. See the exact change on the GitHub PR here.

You can take one of two paths to solve this:

  1. Upgrade flask

  2. Pin your werkzeug version

# in requirements.txt
werkzeug==2.0.3
like image 58
Christian Di Lorenzo Avatar answered Sep 02 '25 05:09

Christian Di Lorenzo


Adding to Christian Di Lorenzo's answer

  1. Upgrade flask
# in requirements.txt
Flask==2.1.1
  1. Pin your werkzeug version
# in requirements.txt
werkzeug==2.0.3
like image 32
Shalin Hudda Avatar answered Sep 02 '25 06:09

Shalin Hudda