Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed yesterday. Improve this question Hi I have write machine learning use decision tree model. I create webapp that user can input and web will call to model by flask api and then show result on webapp but my result have only Yes/No. It possible if the result can show percentage how much this input will yes/no, Example Yes 76% Answer You could use predict_proba() as it
I’m creating the engine and the Metadata as follows Yields AttributeError: packages, and dir(Base.classes) returns no attributes with that name, neither with the orders name. Taking the only=[‘orders’, ‘packages’] off makes it reflect only a few random tables. Now, when using the inspector that comes with native SQLAlchemy the table actually works (link to documentation): Is this a bug, or am I overlooking something here? Thanks! Installed package versions: Answer SQLAlchemy’s automap extension only reflects tables which have defined primary keys. From the note in the docs: […] for a table to be mapped, it must specify a primary key.
I am writing an app in python flask-sqlalchemy with MySQL DB (https://flask-sqlalchemy.palletsprojects.com/en/2.x/) and I am wondering if I have to make “db.session.commit() or db.session.rollback()” after GET call, which only query DB . For example: Answer orders = Order.query.all() is a SELECT query that could be extended to include additional filters (WHERE etc.). It doesn’t alter the database, it simply reads values from it. You don’t need to commit on a read for precisely that reason – what would you store other than “I just read this data”? Databases are concerned about this in other ways i.e. access permissions and logs.
I’m deploying a python3 flask application in aws elasitc beanstalk (Amazon Linux 2 platform). The folder structure is as follows: In the template files, importing of static resources are defiled as: i.e. JS file: In the EB configurations, I’ve defined the static resources as below But the problem is, these resources are not loading and giving 404. i.e.: https://example.com/static/js/jquery.js cannot be loaded. But if I try https://example.com/js/jquery.js, it works. Have I done the configurations wrong?? Answer Based on the comments. The issue was due to overwriting /static path. In python EB environments, /static path is used by default to server
In a flask app, I was trying to iterate through objects in a S3 Bucket and trying to print the key/ filename but my_bucket.objects.all() returns only the first object in the bucket. It’s not returning the all the objects. The output is [001.pdf] instead of [001, 002, 003, 004, 005] Answer You are exiting the loop by returning too early.
I am trying to convert Canadian Postal codes into lat, long coordinates however geopy returns them as either none or somewhere in a different country Output AttributeError: ‘NoneType’ object has no attribute ‘latitude’ OR some random address Answer I think the problem here is either the API you use for geopy does not support for CA zip code, or you don’t set ‘CA’ as the country option. So when the geocode can’t retrieve the info from the input, it returns None. To achieve the same goal, I would prefer use pgeocode library.
I have a container that runs a Python program and it can run in two ways, using docker exec in the localhost terminal or by making an API Rest request (that is outside the container) which executes the same command as it would be done by using the first method. What I am trying to do is whenever my Python program inside the container raises an error the API notice it. The error handling that is being done in the Python program is using logging.exception to print an error message and the traceback in terminal and in the API I
I have a file db_table.py that looks like: When I try to run: I get: I tried first manually setting FLASK_APP var, by doing set FLASK_APP=app.py then running flask db init again, but that didn’t resolve the issue. Answer The flask command line argument needs to know what module to locate the current Flask app instance in. Set FLASK_APP as an environment variable: before running your flask command-line app. See the Command Line Interface documentation: For the flask script to work, an application needs to be discovered. This is achieved by exporting the FLASK_APP environment variable. It can be either
I am debugging a microcontroller I’ve built which is writing raw HTTP requests line by line. I am using Flask for my backend and I would like to see the entire request as it appears in this format: I know Flask is based on WSGI. Is there anyway to get this to work with Flask? Answer With flask you have access to the request object which contains all the HTTP details:
If app.secret_key isn’t set, Flask will not allow you to set or access the session dictionary. This is all that the flask user guide has to say on the subject. I am very new to web development and I have no idea how/why any security stuff works. I would like to understand what Flask is doing under the hood. Why does Flask force us to set this secret_key property? How does Flask use the secret_key property? Answer Anything that requires encryption (for safe-keeping against tampering by attackers) requires the secret key to be set. For just Flask itself, that ‘anything’