I have a Django app (Python 3.4, Django 1.7) on PythonAnywhere, along with a MySQL database.
The database is working fine on the deployed app.
However, I cannot get to connect it to the app on my local machine.
The following error is thrown when I run python manage.py runserver:
django.db.utils.InterfaceError: (2003, "2003: Can't connect to MySQL server on 'mysql.server:3306' (8 nodename nor servname provided, or not known)", None)
These are the attributes I use:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': '<username>$<database_name>',
'USER': '<username>',
'PASSWORD': '<databse_password>',
'HOST': 'pythonanywhere.com'
}
}
I have also tried mysql.server and mysql.server.pythonanywhere.com as HOST without any more luck.
I think It's not possible to connect directly to your mysqlserver instance from remote, for security reason, the port 3306 is blocked.
They suggest to connect through SSH Tunnel, follow this link.I don't know If you can do an ssh tunnelling within Django, You should probably write a custom configuration. It's simpler to install an SSH Tunnel software on your PC and then connect your Django App to localhost on a port You have to choose.
Bye
As per PythonAnyWhere documentation :
Open a terminal and run below command.
ssh -L 3333:username.mysql.pythonanywhere-services.com:3306 username#ssh.pythonanywhere.com
provide your PAW account login password
replace username with your username.
Open another terminal and run below command.
mysql -h 127.0.0.1 --port 3333 -u username -p
provide your mysql password. Available in settings file.
keep terminal 1 open as long as you are working on terminal 2.
Accessing PythonAnyWhere MySQL from outside
Only Paid account have permission to access remoteserver for mysql database
Related
I am trying to run a Django application on AWS Ec2 instance. I've chosen Ubuntu as my platform. After cloning the git repository, and creating a virtual environment, I have installed all apps in my requirements.txt. When I try to the following lines of code python3 manage.py migrate ; python3 manage.py check ; python3 manage.py runserver the following error is coming up.
django.db.utils.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "columbus_db" connection to server at "localhost" (127.0.0.1), port 5432 failed: FATAL: password authentication failed for user "columbus_db"
My settings.py file looks like this
DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Database Engine of PostgreSQL Database
'NAME': 'columbus_db', # Database Name
'USER': 'columbus_db', # Database has a Root User
'PASSWORD': 'columbus', # Database Connection Password
'HOST': "localhost", # IP Address for Localhost
}
What can I change in settings.py or Ec2 Instance settings to start the application and see it at Ec2 IP address?
You are missing a running database, the app code except it to be PostgreSQL, you have multiple choices:
Install and run a local PostgreSQL instance directly in your EC2
Use Amazon's managed database RDS
Use Sqlite which is simple to setup and doesn't require more configuration, but your app might required specific PostgreSQL features
I'm using Django + mysql for days. And this morning I suddenly found that I cannot get connect with the remote mysql.
% python manage.py makemigrations
it raise
django.db.utils.OperationalError: (2026, 'SSL connection error: SSL_CTX_set_tmp_dh failed')
also when
python manage.py runserver
Here's my environment:
macOS 10.15 + Django 2.2.6 + MySQL 5.7 (on a remote server, ubuntu 18.04) + python 3.6.8 (use conda env)
I've looked for some solutions like:
downgrade openssl
Package openssl conflicts for:
openssl=1.0.2r
python=3.6.8 -> openssl[version='>=1.1.1a,<1.1.2a']
add use_pure=True in my .conf file
nothing changed
add skip_ssl in my .conf file
nothing changed
note
On the server (which I deploy my site, ubuntu 18.04) my site run well using gunicorn + Nginx
All the things worked well until today.
The site broke when I found this issue but work well when I restart it.
I guess maybe some update on the server (automatically upgrade) to cause the problem, but haven't find it yet.
some of my code
# setting.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'OPTIONS': {
'read_default_file': mysqlPath,
'init_command': 'SET default_storage_engine=INNODB',
},
}
}
# my_remote.cnf (which define the 'mysqlPath' in setting.py)
[client]
database = mydatabase
user = myusername
password = mypassword
default-character-set = utf8
host = myremotehost
port = 3306
use_pure = True
skip-ssl
skip_ssl
skip-ssl = True
skip_ssl = True
It is because your server isn't set up for SSL (yet). Thus, the error is caused on the server-side.
As already mentioned and tried successfully, a solution is to either make the server SSL-ready or set skip_ssl to true while in development.
https://dev.mysql.com/doc/refman/5.7/en/using-encrypted-connections.html
I haven't ran project for long time, so there possibly happened some kind of conflict.
When I am trying to run the django + postgresql localhost server by python manage.py runserver get this in response:
django.db.utils.OperationalError: FATAL: no pg_hba.conf entry for host "172.17.0.1", user "thekotik", database "fuck3", SSL off
Normally it should run on 127.0.0.1:8000, but it seems that because of different project that ran on 127.0.0.1:5000 of because of installing docker, it's now somehow broken.
So how to fix this error? How to run it again on 127.0.0.1:8000?
EDIT: In pg_hba.conf :
#local replication postgres trust
#host replication postgres 127.0.0.1/32 trust
#host replication postgres 172.17.0.1 trust
#host replication postgres ::1/128 trust
try this:-
Add or edit the following line in your postgresql.conf :
listen_addresses = '*'
Add the following line as the first line of pg_hba.conf. It allows access to all databases for all users with an encrypted password:
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all all 0.0.0.0/0 md5
I had the same issue before and I solved it by changing IPv4 local connections in pg_hba.file to
host all all all trust
and it solved the problem
So I open the psql terminal (on Windows). I log into it with the server set on localhost,
But when I try to log into it with my production host:
xxxx.compute-1.amazonaws.com
I get the following error:
> psql: FATAL: password authentication failed for user "postgres"
> FATAL: no pg_hba.conf entry for host "128.6.37.14", user "postgres",
> database "campus", SSL off
I tried adding it to the pg_hba.conf, but no luck:
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 128.6.37.14/32 trust
Any idea what the issue is? Is the host correct? It's what I got when I ran heroku config
How do I fix this?
I assume you are using Heroku Postgres, the Heroku Database as a Service based on PostgreSQL, right?
If so, you can use the heroku pg:psql CLI command to connect to your Heroku Postgres database from outside of Heroku.
First, issue the following command to get your Heroku Postgres Add-on name:
heroku pg:info
Then you can do:
heroku pg:psql <Add-on>
e.g.
heroku pg:psql postgresql-parallel-XXXXX
After installing Tryton 3.0 from the ppa:rayanayar/tryton-3.0, as in the gist script on https://gist.github.com/sharoonthomas/5857450, I always get "wrong server password" when trying to create a new database via the Tryton Client.
Why is that? I've entered the global database admin password in /etc/trytond.conf as prescribed:
# Configure the Tryton server password
admin_passwd = my_admin_password
I've checked that
the tryton user exists in postgreSQL and as Linux user and has his name and password in trytond.conf
the PostgreSQL server ist restartet
root#Tryton:~# service postgresql restart
* Restarting PostgreSQL 9.1 database server [ OK ]
the Tryton server is restarted and running
root#Tryton:~# sudo /etc/init.d/tryton-server restart
* Restarting Tryton Application Platform trytond
start-stop-daemon: warning: failed to kill 50063: No such process
[ OK ]
root#Tryton:~# ps aux | grep trytond
tryton 37312 0.2 1.0 292796 17368 ? Sl Mar01 7:45 /usr/bin/python
/usr/bin/trytond --config=/etc/trytond.conf --logfile=/var/log/tryton/trytond.log
root 40178 0.0 2.0 576524 34776 pts/4 Sl+ Mar01 0:03 gedit /etc/trytond.conf
root 50332 0.0 0.0 8112 896 pts/6 S+ 10:45 0:00 grep --color=auto
trytond
python is listening on port localhost:8000
root#Tryton:~# netstat -tupan | grep python
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
37312/python
the client shows the "create" button when entering "localhost" and "8000" in "Create profile"
This is so odd.
After resetting the admin password in trytond.conf to the standard "admin" the login worked again.
The "Creating database" info known from version 2.2 was skipped, the database was created, and in the "Configuring database" dialog a password was asked again (without hint which one), and it turned out to be the local database admin password (means the password created for the admin user of the newly created database).
Somewhat strange, but seems to work locally.
However, no connection via internet yet.
Internet connection solved as well.
It turns out in the end that the documentation for Ubuntu installation (on https://code.google.com/p/tryton/wiki/InstallationOnUbuntu), that currently refers the user to Debian installation, would benefit hugely from having the additional detail given in the installation for e.g. Gentoo, cause they have the actual working config file complete with postgre server settings, which was the decisive point in the end.
See http://wiki.gentoo.org/wiki/Tryton.
I already had
# Activate the json-rpc protocol
jsonrpc = localhost:8000
And after adding this, it worked like a charm:
Configure the database connection
## Note: Only databases owned by db_user will be displayed in the connection dialog
## of the Tryton client. db_user must have create permission for new databases
## to be able to use automatic database creation with the Tryton client.
db_host = localhost
db_port = 5432
db_user = postgres
db_password = postgrsqlpassword
db_minconn = 1
db_maxconn = 64
In my case, I have tryton as database user, some instructions prefer this, obviously for security reasons. By using postgres (the built-in master administrator for PostgreSQL) as database user, you can circumvent having to add the tryton role to postgres (the standard package install with apt-get on Ubuntu adds that automatically anyway iirc).