Skip to content

bottle

requests

request.headers

type bottle.WSGIHeaderDict is different from dict

Troubleshooting

Object of type "ModuleType" is not callable

Pyright cannot infer correct type for Bottle()
In VSCodium, in settings, uncheck Workspace/UseLibraryCodeForTypes

Debug

Debugging a Bottle (or Flask) application underlies that a process can handle request and call route handlers.
To do so, a solution is to create a simple app:

from bottle import Bottle
import io
import json

import somewhere


def add_route(app, route, method, fn):
    app.route(route, method, fn)
    return app


def request_post(app, fn, data):
    add_route(app, '/', 'POST', fn)
    post = json.dumps(data).encode()
    # content_length is crucial
    request_data = {
        'REQUEST_METHOD': 'POST',
        'PATH_INFO': '/',
        'CONTENT_TYPE': 'application/json',
        'wsgi.input': io.BytesIO(post),
        'CONTENT_LENGTH': str(len(post))
    }
    return app.wsgi(request_data, lambda *args: None)


def request_user_login_create(app):
    fn = somewhere.v1_user_login_create
    data = {
        'USER_LOGIN': 'john.smith@unknown-llp.com'
    }
    return request_post(app, fn, data)


app = Bottle()
request_user_logincreate(app)