I have been moving my flask apps from replit to my server, and things have been going smoothly, but I am moving my first app with SQL in it over to the server, and there keeps being errors when I open the database in the code. In the Apache error log, it says:
sqlite3.OperationalError: unable to open database file
The app works well on replit, the database is in the same folder, but it doesn't work. Does anybody know why? I am using Ubuntu Server 20.04
I have figured out why it's not working! The database was in the same dir as init.py, but wsgi calls it as a module in a different dir, so it wasn't calling the db. Adding an absolute path eg. /var/www/theapp/theapp/database.db works.
Related
Hi I have deployed a Flask (ML Project) in Heroku cloud and the app is published. But when I try to predict the model, it gave an error of database connection. When I debug I found out that the connection to the cassandra db is not working. Here was my code
self.cloud_config = {'secure_connect_bundle': "cassandraconnection\\secure-connect-test.zip"}
self.auth_provider = PlainTextAuthProvider('XXX','XXX')
self.cluster = Cluster(cloud=self.cloud_config, auth_provider=self.auth_provider)
The secure-connect-test.zip file is located in the project directory itself. But still i am getting the error
No such file or directory: 'cassandraconnection\\secure-connect-test.zip'
Can anyone suggest where I am making the mistake. Or how to solve this issue
It's very likely that where you think the secure bundle should be and where Heroku is looking for it don't match.
We recommend that you always specify the full path to your Astra DB secure connect bundle to avoid confusion. Cheers!
I've made a flask project that worked without errors. Once I moved it to a ubuntu virtual machine for deployment, trying to deploy it using gunicorn/ nginx or apache2/ mod_wsgi raises the same error:
conn = sqlite3.connect('../db/bandwidthburst.db', check_same_thread=False)
sqlite3.OperationalError: unable to open database file
On similar questions the advice was to make sure the user has write permissions, so I've done 'chmod ugo+rwx' for my database, its parent folder and the parent folder to that aswell, which did not change the results.
Any help in fixing this would be much appreciated, thank you.
Now connects after changing the url to '/var/www/.../bandwidthburst.db'!
Going through fixing other errors now
I tried to create a sqlalchemy project in pyramid and when I run the server, I get this error,
Pyramid is having a problem using your SQL database. The problem
might be caused by one of the following things:
1. You may need to run the "initialize_MyProject_db" script
to initialize your database tables. Check your virtual
environment's "bin" directory for this script and try to run it.
2. Your database server may not be running. Check that the
database server referred to by the "sqlalchemy.url" setting in
your "development.ini" file is running.
After you fix the problem, please restart the Pyramid application to
try it again.
when I check my development.ini file the sqlite database is configured as this,
sqlalchemy.url = sqlite:///%(here)s/MyProject.sqlite
What needs to changed in here to configure it correctly?
I run on linux box.
You need to create a database in either sqlite,postgres,or any other,Thereafter go to development.ini file edit sqlalchemy.url = sqlite:///%(here)s/MyProject.sqlite and specify the name of your database,then run the initialize_myproject_db development.ini command.if you are using mysql, that line should be
sqlachemy.uri = mysql://username:password#host/dbname
Just trying Pyramid for the first time, I just faced the same problem, after many command combinations, I just got the solution.
Run from the project root, the command:
initialize_tutorial_db development.ini
Info taken from Wiki2 SQLAlchemy tutorial
It says right there in the first point - you need to run initialize_MyProject_db development.ini to create database.
If that's not the case please post the log from running the server.
I've made a simple Flask app which is essentially a wrapper around sqlite3. It basically runs the dev server locally and you can access the interface from a web browser. At present, it functions exactly as it should.
I need to run it on a computer operated by someone with less-than-advanced computing skills. I could install Python on the computer, and then run my .py file, but I am uncomfortable with the files involved being "out in the open". Is there a way I can put this app into an executable file? I've attempted to use both py2exe and cx_freeze, but both of those raised an ImportError on "image". I also tried zipping the file (__main__.py and all that) but was greeted with 500 errors attempting to run the file (I am assuming that the file couldn't access the templates for some reason.)
How can I deploy this Flask app as an executable?
Host it.
Since you created it in Flask, and its a web app - hosting it should be trivial. Dump it on any of the PaaS providers like Heroku, Google App Engine, OpenShift or spin up a micro instance on EC2 and host it there.
Creating an executable is not the solution.
Why distribute it at all? If the user you want to use it is on the same local network as the Flask application, just give them the IP address and they can access it via a browser just as you are doing, and no access to the source code either!
recently I started a small Django project that I developed on a local machine using a SQLite3 database and the integrated development server. I now copied the whole project to a server running Debian.
Everything worked well as long as I kept using the SQLite3 database. Now I wanted to switch to a local MySQL database, so I changed the settings.py file in my project's root folder, created the database and added a user. I then ran syncdb and it created the needed tables without any problems.
Now I wanted to use the app, but I keep getting errors, because Django can not find the tables - neither the 'standard tables' like django_sessions nor my own tables - even though they are there (I checked the database).
The one thing that seems awkward about the DatabaseError pages I get is the following line:
Exception Location: /usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py in execute, line 234
It seems like Django is still using the SQLite3 backend even though I set it to use the MySQL backend.
The other thing that nearly makes me freak out is this: I deleted the data.sqlite file in my app's root folder using rm. But when I use my app, the file is being recreated!
Can anyone tell me where I went wrong?
When running in production with mod_wsgi or mod_python, new code isn't incorporated until you reload/restart the webserver.
If you are using apache with mod_wsgi, you can also touch the wsgi.py file to restart the python code only.
If running on apache run "sudo /etc/init.d/apache2 reload" everytime you make a change.