How to acces database in heroku - python

So I have created a website with Flask and uploaded it to heroku.
The website has a database which is called test.db
In cmd i did
heroku vim -a my-app;
so now when I do dir, I get all my files, and test.db too. But how to open test.db, i tried open or read test.db. None of those seem to work. Do you know a command to open this database file?

Copy it via heroku ps:copy filename to local machine. Open it on local machine as usual.
Though in general you shouldn't rely on a database that is written to file system because on Heroku your files will be wiped once every day.

Related

Uploading files to IPFS in an Heroku Flask app

Good afternoon,
I have troubles with the IPFSHTTPCLIENT library for Python when uploading files to IPFS. It worked when I was running the app on a localhost environment. However, in Heroku, it doesn't, and I guess that it's because of the IP addresses. These are my current config variables and I don't know what should I put in order to make IPFS work again.
IPFS_CONNECT_URL = /ip4/127.0.0.1/tcp/5001/http
IPFS_FILE_URL = http://127.0.0.1:8080/ipfs/

Flask not opening SQLite Database on apache2

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.

No such file or directory exists Error from server request

Actually my flask app runs fine in local host but after deploying it to server,I used pythonanywhere to deploy my flask web app it got some errors.
My motive is to send a path of a file from input and python takes the path and uses to locate the file and perform some operations on the data(excel file),if works good in local host.But in server it says no file or directory exists
address=request.form['address']
file_location =address
workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
psitrnid = int(sheet.cell_value(9,4))
psiootid = int(sheet.cell_value(9,5))
goodtrnid = int(sheet.cell_value(9,7))
badtrnid = int(sheet.cell_value(9,8))
goodootid = int(sheet.cell_value(9,10))
badootid = int(sheet.cell_value(9,11))
The file_location variable will have the path of file and xlrd uses it open and read it.
I don't know what is causing this error but I want to know whether we can access a local file using xlrd or pandas from server or cloud app.
Does the server perform request or the system allow the web app to take the file by mentioning the path.
Your Flask code only has access to files that are stored on the machine where it is running; when you run it locally, it has access to files on your local machine, but if you run it on a server like PythonAnywhere, it will only have access to files that are stored on that server. If you want people to be able to specify files on their local machine and have your code process those files, you'll need to implement code to upload the files to the server. If you google for "upload file flask" you will find useful guides on how to do that.

Using pg_restore on dump file

I have a database on Heroku I'm trying to copy to my local machine.
I created a backup of the database by doing:
heroku pgbackups:capture
This create a dump file of the database which I downloaded by creating a URL link to it:
heroku pgbackups:url b004
But now I have a dump file and don't really know what do to with it. I tried
pg_restore
to restore the database but I don't know where that information went. I basically want to create a .db file out of this dump file. Is that possible?
Ultimately my end goal is to access this database -- so if another method of copying the db is better, I'm fine with that that.
Heroku does not allow you to use sqlite files, as they have a read only file system. But you can use Django to dump the data from Heroku into a JSON file via the dumpdata command, and them import that into your local dev environment.
Because it can be difficult to run commands that generate files on the web server using heroku run, I suggest you instead install django smuggler, which makes this operation a point and click affair in admin.
First of all you should install postgres in your local machine.
PostgreSQL cheat sheet for django beginners
Then, import your dump file with pg_restore command:
pg_restore -d yournewdb -U yournewuser --role=yournewuser /tmp/b001.dump
Thats all, your data is now cloned from your heroku app.

How to empty Google App Engine's local database

Where do I go to delete everything in my local db?
I saw this: http://fourtyten.blogspot.com/2009/07/how-to-empty-google-app-engines-local.html
But my WEB-INF directory doesn't have a local_db.bin
I saw this post also How to delete all datastore in Google App Engine?
If you're talking about the development datastore, you'll just have to delete the following file: "./WEB-INF/appengine-generated/local_db.bin". The file will be generated for you again next time you run the development server and you'll have a clear db.
But I can't find this folder either.
--Update---
I found this post How do I delete all entities from my local Google App-engine datastore? and it looks like I can use dev_appserver.py --clear_datastore dennys
But when I run that I get this python dev_appserver.py --celar_datastore dennys
python: can't open file 'dev_appserver.py': [Errno 2] No such file or directory
How do I find where dev_appserver.py is on my machine?
To delete data follow the steps here: http://code.google.com/appengine/docs/python/tools/devserver.html#Using_the_Datastore
This question is not longer valid, my problem is listed here: AppConfigNotFoundError for dev_appserver.py on Django-nonrel and Google App Engine
Open up a terminal and execute the following
cd /
find . -iname "*dev_appserver.py*" -type f
then add that to your path in your .bash_profile as so
PATH=$PATH:<directory from previous command>
then use the dev_appserver.py as you had previously mentioned like so
dev_appserver.py --clear_datastore=yes <your app's directory>
Keep in mind that python dev_appserver.py <your_app> might not work

Categories

Resources