My django project runns normally on localhost and on heroku also, but when I deployed it to google cloud platform I am getting this error:
could not connect to server: Connection refused
Is the server running locally and accepting connections on Unix domain socket "/cloudsql/<connection_name>/.s.PGSQL.5432"?
The connection to the database in settings.py looks like this:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'database_name',
'USER': 'postgres',
'PASSWORD': "password",
# production
'HOST': '/cloudsql/connection_name',
'PORT': '5432',
}
Additionally, my app.yaml looks like
runtime: python37
handlers:
- url: /static
static_dir: static/
- url: /.*
script: auto
env_variables:
DJANGO_SETTINGS_MODULE: fes_app.settings
requirements.txt looks like this plus
sqlparse==0.4.2
toml==0.10.2
uritemplate==4.1.1
urllib3==1.25.11
whitenoise==5.2.0
twilio==6.9.0
I have tried using the binary version of psycopg, also gave a role client sql to the service account in the cloud.
**NOTE : ** I am using an app engine standard environment
Likely need more information to help you out, but did you follow the tutorial below in the official Google Docs? That's usually how I get started and then I make modifications from there.
I would compare how Google is deploying a Django app to your own settings and see what's missing. For example, your requirements.txt file does not look complete (unless you only pasted part of it) so I would start there.
https://cloud.google.com/python/django/appengine
my DB connection is
DATABASES = {
'default': {
'ENGINE': 'djongo',
'ENFORCE_SCHEMA': True,
'NAME': 'taxiapp',
'HOST':'127.0.0.1',
'PORT': xxxx,
}
}
my SSH ADDRESS x.x.x.x
SSH USERNAME 'admin' SSH PORT 0000 SSH AUTH method password and USER PASSWORD 0000
currently, I am getting
pymongo.errors.ServerSelectionTimeoutError: 127.0.0.1:xxxx: [Errno 111] Connection refused
How to define SSH details in my settings.py file ???
You can use Paramiko library for this.
it works pretty well.
here is good explanation of how to set it up.
https://hackersandslackers.com/automate-ssh-scp-python-paramiko/
don't hesitate to forward encountering problems once you do it.
I am trying to use my localhost database inside docker Django container.
I have allowed listen_address to all in postgresql.conf file.
I have added host all all localhost,192.168.1.9 trust in pg_hba.conf file.
192.168.1.9 is my en0 address.
Now i want to use 192.168.1.9 as my host in database setting in django.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'db_name',
'USER': 'db_user',
'PASSWORD': 'db_password',
'HOST': '192.168.1.9',
'PORT': '5432',
}
}
I am trying this but i am not able to succeed.
Am i doing something wrong? I want postgres to accept all connect so Django app container can connect to my local machine database.
I am trying
psql -h 192.168.1.9 -U db_user -d db_name
Getting psql: could not connect to server: Permission denied
Is the server running on host "192.168.1.9" and accepting
TCP/IP connections on port 5432?
I am not sure what wrong i am doing.
the docker containers are usually on separate network interface (docker0), so if your app wants to access your host you have to use the docker0 interface.
you can get the ip of host from your container with
/sbin/ip route|awk '/default/ { print $3 }'
I am trying to deploy my Django project on my company LAN. I am able to get the site working. However, I lose connectivity to my Microsoft SQL Server when I run the site through Apache. Everything works fine in the development environment. I suspect that I am losing Windows authentication when I work through the Apache server. This is what my DB settings are in my settings.py file:
'mosaiq': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'MOSAIQ',
'USER': '',
'PASSWORD': '',
'HOST': 'HHCMOSAIQ01T',
'PORT': '',
'OPTIONS': {'driver': 'ODBC Driver 11 for SQL Server',
},
Any idea how to connect to my SQL Server using Windows authentication or does my problem lie elsewhere?
This is the error I get:
('28000', "[28000] [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'MEDSTAR\$'. (18456) (SQLDriverConnect)")
I normally use Postgres for my database needs with Django but I recently started at a company which use MSSQL on a Windows environment. Long story short I had to rewrite the database properties in settings.py. Unfortunately, I have NO idea how to connect to a SQL Server using Pyodbc and they're running Python 3.x so I can't use Django-Pyodbc. While trying to run it I'm getting a:
"Data source name not found and no default driver specified (0) (SQLDriverConnect)')"
Here is my current db config as it stands. I'm probably doing something wrong but it is very difficult to find resources since most Django+Sql Server results either use FreeTDS or Django-Pyodbc (neither are options).
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'db_name_on_server',
'USER': 'my_acct',
'PASSWORD': 'nope',
'HOST': 'x.x.x.x',
'PORT': '1433',
'OPTIONS': { # Options are not edited
'driver': 'SQL Server', # What it displays as on odbc admin
'dsn': 'System DSN', # What it displays as on odbc admin
'use_legacy_datetime': False
}
Old question, but it might help someone. These are the settings I use in Windows to connect to a SQL Server. As #flipperpa said, I also use django-pyodbc-azure
pyodbc==3.0.10
django-pyodbc-azure==1.10.0.1
However, the pyodbc that pip will download doesn't work for me. As suggested in this answer, go this site http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyodbc and download either depending on the version of Python 3.5 you have installed:
pyodbc‑3.0.10‑cp35‑none‑win32.whl if you have a 32-bit Python 3.5 install
pyodbc‑3.0.10‑cp35‑none‑win_amd64.whl if you have a 64-bit Python 3.5 install
Then use these settings to connect:
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': "localhost",
'USER': "--user name--",
'PASSWORD': "--password--",
'NAME': "--database name--",
'PORT': 1433,
'OPTIONS': {
'driver' : 'SQL Server Native Client 11.0',
'MARS_Connection' : True,
'driver_supports_utf8' : True,
},
}
For anyone that is using linux, MS has now released official odbc drivers for SQL server and is officially (if more than a little tacitly) supporting the django-pyodbc-azure project. I highly recommend using it and also the native linux SQL Server ODBC driver over FreeTDS.
I've had my best luck with the following stack, and we're a Python 3 shop exclusively:
FreeTDS 0.95
pyodbc 3.0.10
django-pyodbc-azure 1.8.3 (assuming Django 1.8+)
Assuming you have odbc.ini, odbcinst.ini, and freetds.conf all squared away, here's an example of settings that work for me. Some of these depend on whether or not you're using SQL Server 2008+:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': 'yourserver.com',
'PORT': '1433',
'NAME': 'your_db',
'USER': 'your_user',
'PASSWORD': 'your_pw',
'AUTOCOMMIT': True,
'OPTIONS': {
'driver': 'FreeTDS',
'unicode_results': True,
'host_is_server': True,
'extra_params': 'tds_version=7.2;',
},
},
}
You'll also need to include 'use_legacy_datetime': True, if you're running SQL Server 2005 or less, otherwise, it will use the new SQL Server 2008+ date fields. It will also automatically set to true if you're using an outdated driver. Good luck!
Official backend fork from Microsoft: Microsoft MSSQL Django
They also have this reference Azure SQL Database Django sample.
Set 'ENGINE': 'mssql' to use it. Example:
DATABASES = {
"default": {
"ENGINE": "mssql",
"NAME": "mydb",
"USER": "user#myserver",
"PASSWORD": "password",
"HOST": "myserver.database.windows.net",
"PORT": "",
"OPTIONS": {
"driver": "ODBC Driver 17 for SQL Server",
},
},
}
Meanwhile there is django-mssql-backend for MSSQL support and this how my settings look like (Django 3.0, django-mssql-backend 2.8.1)
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD': os.getenv('DB_PASSWORD'),
'HOST': os.getenv('DB_HOST'),
'PORT': os.getenv('DB_PORT'),
'TEST': {
'NAME': os.getenv('DB_NAME'),
},
'OPTIONS': {
'driver': 'ODBC Driver 17 for SQL Server',
'extra_params': 'MARS_Connection=Yes'
},
}
}