I have been tasked with migrating a python web application to another Linux server. Frustratingly, the entire database is sqlite3. I have moved all related code and database files to the new server and set up the environment. Python does not seem to be able to open the database files as I get this message when running the app:
OperationalError: unable to open database file
I have checked the following:
All paths are correct, the database connection is made.
Read/Write permission is open to all users on the files for testing
One difference between the servers is, the old server has sqlite 3.5.6 and the new one has 3.6.20. Would there be file compatibility issues here? If so, is there a way to convert the database files to be compatible? Is there another problem I may be overlooking?
The error message
OperationalError: unable to open database file
may occur if the directory containing the database file is not writable.
To make the directory writeable for $USER:
chmod o+w /path/to/dir
chown $USER /path/to/dir
Related
I have a problem that I've been trying to solve for a very long time and it seems like I'm missing something very basic.
I use a Linux server with Anaconda, Oracle client, Pycharm and jupyter-notebook installed.
I use python scripts in which I write and read data to Oracle DB, and I use the Cx_oracle extension.
The server has several users with a personal username for each and each of them has sudo privileges.
I performed all the installations on the server with sudo privileges.
When I try to connect from the server to Oracle DB I connect properly.
When I connect to Python on the server itself, I connect properly to Oracle DB.
When I connect using Pycharm and I define ORACLE_HOME=/OracleTools/19.0.0/ in the environment variables, I connect properly to the Oracle DB.
My problem starts when I want to use jupyter-notebook
When I try to connect to the DB I get the error -
DatabaseError: Error while trying to retrieve text for error ORA-12715
I noticed when I execute os.environ I see that it is defined for me:
ORACLE_HOME: /OracleTools/19.0.0/bin
and should be
/OracleTools/19.0.0
So I changed using command os.environ['ORACLE_HOME'] = '/OracleTools/19.0.0'
Then I get an error:
DatabaseError: ORA-12715: invalid character set specified
And of course this change is not permanently saved ...
If on the server itself I execute the env command both in the private user and in sudo I see ORACLE_HOME: /OracleTools/19.0.0 and not ORACLE_HOME: /OracleTools/19.0.0/bin
My questions:
Where does the data I get in the os.environ command come from?
How can I edit them permanently ?
Is this even the problem I'm having or should I check something else?
I manage to import cx_oracle, which means that there is no problem of expansion
Thanks!
I am trying to connect to a Postgres database from a Jupyter Notebook using the psycopg2 library.
First of all, I installed it:
conda install psycopg2
Looks fine. Next step was try to connect to by database in cloud:
import psycopg2
conn = psycopg2.connect(#my_database_credentials)
And I got error like:
FATAL: no pg_hba.conf entry for host...
I am starting to find this file, and found two on my computer. One in /UserName/Anaconda3/Library/share and one in /UserName/Anaconda3/libpq-11.2-h3235a2c_0/Library/Share
So, I changed both files in several different ways, for example:
# TYPE DATABASE USER ADDRESS METHOD
local all all trust
host all all all trust
But I still got the same error. So my question is:
What else do I need to install? Or maybe I need to configure other files? Or what I need to do to connect to the database. Thank you
I'm attempting to connect to an Access .mdb database with Python pyodbc. I connect to a local database, and this works fine. The database contains linked tables to a back end .mdb on a network drive. I receive this error when attempting to select from the linked table:
pyodbc.Error: ('HY024', "[HY024] [Microsoft] [ODBC Microsoft Access Driver] 'U:\OFFICE\GIS\accessdatabase.mdb' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides. (-1023) (SQLExecDirectW)")
The path name is correct, and the linked tables work fine if I go into my local database and open them. The python program never mentions the network database or it's path at all, it only connects to the local database.
The python script works fine. I'm only getting the error when running the compiled .exe generated by Pyinstaller. Also, a coworker can compile on Windows 10 and his .exe works fine. But it has to compile on Windows 7 to produce an .exe that works on Windows 7.
Windows 7.
conn_str = (
r'DRIVER={Microsoft Access Driver (*.mdb)};'
r'Uid=Admin;Pwd=;'
r'DBQ=' + self.path
)
Any assistance or pointers would be greatly appreciated! Thanks
Not sure if this is an answer exactly, or more of a work around, but I got it to work by re-linking the remote database tables using '\server\name\path' style paths in the local database, instead of 'U:\path' style ones. Apparently the compiled program was trying to run as administrator for some reason, and in command window the mapped drives were unavailable when running as administrator. Figured I would share in case anyone else has a similar issue.
I've saved a .pgpass (properly configured) file in
`/Users/username/`
`/anaconda`
`/anaconda/bin/`
but the postgresql connection still requests my username and password. I'm using Anaconda and Spyder IDE. Where should I save the .pgpass file?
Like the documentation says:
The program must be using the C client library libpq to connect to PostgreSQL (the JDBC driver, for example, doesn't use libpq).
The .pgpass file must be in the home directory of the user that owns the process which uses libpq to connect to PostgreSQL.
You can override the default location by either putting the variable PGPASSFILE in the process' environment or (from v10 on) with the connection parameter passfile.
The .pgpass file must have permissions 0600 or less.
Check permissions. The .pgpass file has to have no group nor other permissions:
chmod u-x,go-rwx ~/.pgpass
A command line psql client would actually warn you about it:
WARNING: password file "/home/tometzky/.pgpass" has group or world access; permissions should be u=rw (0600) or less
I would like to get started with working with python and PSQL databases.
The script I have in mind will (at least not at the beginning) run on hosts with an installed PSQL Database, but I want the script to connect remotely to the database.
In fact (for the start):
user hosts: run the script (read xls, convert, manipulate, etc) and write into remote DB
DB Host: this will host the db and gets connections from the user hosts and the "Sync Host"
Sync Host: a cloud service which will connect to the db server to read the databases and do some "magic" with it.
from what I have read, the best python module for PSQL connection is psycopg, but this seems to require an installed PSQL Database, which is something I do not have (and don't want to install) on the user hosts.
At a later stage I will remove the "user hosts" and provide a webinterface for uploading the xls and do the conversion, etc on the db host, but for the beginning I wanted to start as mentioned above.
My questions:
Is my thinking totally wrong? should I start with a central approach (webinterface, etc) right awa
If not, how can I get a PSQL connection method implemented in python without installing a PSQL Database?
All User hosts are Mac OS X, so Python is already installed.
thanks a lot in advance
Andre