Python cannot access environment variables while running any command. For example, after running
python3 manage.py migrate
an error occurs:
django.db.utils.OperationalError: (2006, "Access denied for user 'dbmasteruser'#'0.0.0.0' (using password: YES)")
But if I insert a plain string value for database password instead of os.environ.get('PASSWORD'), command works fine.
All environment variables are written in setenv.sh file, but I have also tried to set them alternatively using command export PASSWORD=password.
Executing command using sudo doesn't work either.
However, Apache deployment server can read those environment variables without any issues, but the problem occurs while running migrations or any other command. How can I solve it?
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!
every time i try to make connection between python and PSQL this error disappear ?
You need to first make sure your DATABASE_URL has been defined before you even run your server. If you are using an online database and have a url, executing the command in terminal (for mac/linux):
export DATABASE_URL = "https://my_database_link"
inside your virtual environment, where you installed python will connect your virtual environment variable to your database online. If you are still experiencing problems. make sure you have installed everything correctly.
I'm trying to get to the django shell so that I can set some superuser permissions for our staff accounts. Doing this by ssh tunneling via ps:exec
We just moved over to heroku, and are using their auto-configured (read: automagical black box) module import django_heroku; django_heroku.settings(locals()) to set database settings.
When I open the shell, those config settings aren't run, and I get an error saying that
django.db.utils.OperationalError: no such table: user
Basically, I can't get the shell instance to use Heroku's nice postgres configurer. Any ideas? Workarounds to manually query accounts and set some params? I've tried to import that same magical module from Heroku as part of the shell and instantiate it, but it only works when run in the settings.py file.
I'm trying to not actually log into the postgres instance so that I don't have to open any IP ranges, etc.
__________edit_________
On a similar note, it looks like the shell also can't load Heroku's env vars... getting some issues there as well. Is there a way to run the shell with Heroku's environment completely?
You can run python manage.py shell directly through the heroku cli:
heroku run python manage.py shell --app=your-app-name
You can access the Django shell through the Heroku Dashboard by using the view console button.
So, you can access your shell (Django shell) or the Linux shell of Heroku directly.
https://www.pythoncentral.io/writing-your-first-python-django-application/
I am following this tutorial on Django for Python. I have reached and installed the mysql-python (mysqlclient in python 3 which I am using) step. However I do not understand what he means by "..execute the following statements in a mysql shell.."
mysql> CREATE USER 'pythoncentral'#'localhost' IDENTIFIED BY '12345';
mysql> CREATE DATABASE myblog;
mysql> GRANT ALL ON myblog.* TO 'pythoncentral'#'localhost';
My problem is I do not know what program I need to enter these commands into.
I have tried imputing the commands in:
cmd.exe at the location of my django folder (myblog)
on the mysql shell (https://dev.mysql.com/downloads/shell/)
In the command window "python -m pip list" shows me mysqlclient is installed, however, python -m mysql (or mysqlclient, mysqldb etc) returns "No module named mysql"
In the mysql shell, I have not been able to run the above commands either but I am less familiar with it compared to the command window.
Any suggestions?
Find out where mysql is installed then move to that folder and run these commands to open the shell
In my case it is
C:\>cd \MYSQL\Bin
C:\MYSQL\Bin>mysql -u root -p admin
'root' is mysql username and 'admin' is my password replace it with you own and you would be able to login and execute those commands.
I am reading this tutorial: Installing and Configuring Graphite and Statsd on an Ubuntu 12.04 VPS
and I am working to automatize everything is possible then there is one step of this tutorial that is giving me crazy:
Next, we will configure the Graphite database. Go to the Graphite
webapp directory and run the database script:
cd /opt/graphite/webapp/graphite/
sudo python manage.py syncdb
As you see, we have to run the manage.py and when I run syncdb ask about a creation of superuser. How can I avoid that? I would like to run these sending all parameters to make an automatic script.
Any ideas?
You can use the --noinput argument to disable those prompts for the syncdb command.
--noinput
Use the --noinput option to suppress all user prompting, such as “Are you sure?” confirmation messages. This is useful if django-admin.py is being executed as an unattended, automated script.