Error in Flask development environment

Asked

Viewed 33 times

2

I created an application in Flask, and can run normally by running only one flask run, but when I spin, it appears that it is in a production environment. When I switch to the development environment, with $env:FLASK_ENV = "development", the application runs, but I get an error whenever I try to make a request.

Here mine __init__.py

from flask import Flask

from .views.mfe import mfe
from .extensions import cors

def create_app(config_file='settings.py'):
    app = Flask(__name__)

    app.config.from_pyfile(config_file)

    cors.init_app(app)

    app.register_blueprint(mfe)

    return app

And here an example of a view:

mfe = Blueprint('mfe', __name__, url_prefix='/cfe')

@mfe.route('/emissao', methods=['POST'])
def create():
    return 'Hello World!'

The error received is as follows::

127.0.0.1 - - [25/Aug/2021 13:38:20] "POST /cfe/emissao HTTP/1.1" 500 -
    Traceback (most recent call last):
  File "C:\Users\Livia\Documents\my-project\env\Lib\site-packages\flask\cli.py", line 354, in __call__
    self._flush_bg_loading_exception()
  File "C:\Users\Livia\Documents\my-project\env\Lib\site-packages\flask\cli.py", line 342, in _flush_bg_loading_exception
    raise exc_info
TypeError: exceptions must derive from BaseException
127.0.0.1 - - [25/Aug/2021 13:38:21] "GET /cfe/emissao?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [25/Aug/2021 13:38:21] "GET /cfe/emissao?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [25/Aug/2021 13:38:21] "GET /cfe/emissao?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [25/Aug/2021 13:38:21] "GET /cfe/emissao?__debugger__=yes&cmd=resource&f=ubuntu.ttf HTTP/1.1" 200 -

1 answer

0

From what I’ve been researching in the flask repository, this seems to be a problem in the library itself but has been fixed. A user opened a ticket in May: https://github.com/pallets/flask/issues/4096

Exceptions are sometimes replaced with "Typeerror: exceptions must derive from Baseexception"

translating:

Exceptions are sometimes replaced by "Typeerror: exceptions must derive from Baseexception"

That is, this exception that you are seeing now may not be the exception that is actually happening in your code, as it may have been replaced by this error in the library.

Here is the correction note that took place on June 22nd and was merged into the master branch:

fix Raising error During cli Lazy loading #4169

https://github.com/pallets/flask/pull/4169/commits/aa6dd09c2cab5eb15a45d73b5ade24b7b4131c5a

However the error solution will only be available in flask version 2.0.2 that has not yet been released:

inserir a descrição da imagem aqui

Still you can download the latest version of flask source code with Pip. First you should uninstall the current version of flask with: pip uninstall flask

after installing from git repository:

pip install git+https://github.com/pallets/flask.git

Note that Pip takes the master code with all the last commits. But if you wish, you can only take up the commit of the fix you need, which is aa6dd09c2cab5eb15a45d73b5ade24b7b4131c5a:

for this just rotate the command like this:

pip install git+https://github.com/pallets/flask.git@aa6dd09c2cab5eb15a45d73b5ade24b7b4131c5a

After that I believe that when you run the flask will be presented the original exception.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.