i'm following this tutorial: http://www.programmersbook.com/page/21/Django-Beginner-Tutorial-Part-I/
and I added the database details (running django.db.backends.postgresql_psycopg2) and i added the template dirs. But when i do
./manage.py syncdb
i get:
self.connection = Database.connect(**conn_params)
psycopg2.OperationalError: could not connect to server: Permission denied
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Any suggestions on how i can fix this please?
Before connecting to database you need to install database server, and configure it for any user to access.
If you want just follow tutorial use SQLite -it's most simple to configure.
Otherwise, install database server of your choose, create database, configure access, make sure that connection details are correct, and/or DB server is up and running.
Best way is try to connect to server via command line.
Related
The project is a django web app, packed on docker containers. For some reason, I cannot run the server and launch it.
when I run "manage.py runserver", this error occurs:
File "C:\Users\andre\AppData\Local\Programs\Python\Python310\lib\site-packages\psycopg2\__init__.py", line 122, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: connection to server at "158.160.17.21", port 5432 failed: Connection refused (0x0000274D/10061)
Is the server running on that host and accepting TCP/IP connections?
What do you think can be done with it? Thank you.
The first line of your error tells me that you're using a locally installed copy of psycopg2, a Python client library for PostgreSQL, to connect to the database. This is happening behind the scenes when Django needs to make that connection, but it's interesting that it's installed locally, rather than in a docker container, given you said your Django webapp is running in Docker.
The third line of your error is very simple: it tells you that
the programme is expecting Postgres to be served on a machine with the IP address 158.160.17.21 on port 5432 (the default port for Postgres)
it isn't there
Now, this IP address is not a default and doesn't refer to your own machine, so it must be something you've provided. An IP lookup suggests it's in Venezuela (does that sound right to you?). Perhaps you are expecting Postgres to be served on a third party machine; if so, you'll need to check that you have the right IP address and that Postgres is being served there.
Otherwise, you'll need to reconfigure Django to seek Postgres elsewhere.
Open Task Manager > Services tab > Right-Click on Mongo > Start.
Now go re-run the server again.
When i run my web_app http://eyobkibret15.pythonanywhere.com/ i get postgresql database connection error like this
"
i have a paid account on the server pythonanywhere.com
i try to edit the pg_hba and postgresql configration file inside my postgresql folder and try to add or create a server in pgadmin 4 with my website ip/host but i get this error
error saving property
Unable to connect to server:
timeout expired
is there any way to solve the problem ?
I am building a web app using Django. I am trying to connect the app to the Azure Database for PostgreSQL.
When I try to make migrations with the command, python manage.py makemigrations from PowerShell, I'm getting this error:
no pg_hba.conf entry for host
What does this error mean?
This error means you've haven't configured PostgreSQL correctly for the user you are trying to connect from Django with.
pg_hba.conf is the PostgreSQL file which contains PostgreSQL users, where from, and how they are able to connect. See here for more details:
https://www.postgresql.org/docs/12/auth-pg-hba-conf.html
You should get the same error when you try to run any Django command which needs to connect to the database, for example, python manage.py dbshell. Good luck!
Our DBA is trying to migrate a Django application's database to a new backend host running Oracle 12. When I put that host's info in the Django settings.py file, I get this error:
DatabaseError: ORA-28547: connection to server failed, probable Oracle Net admin error
The DBA has asked for my help in solving this problem. Is there a way to turn on detailed logging in Django while establishing a database connection? I've seen directions for enabling logging of database queries, but we're not getting that far -- our error is happening sometime during the connection.
Basically you can use a Wireshark or any sniffing tool to check what is the connection string passed to the DB.
But this oracle error will occur when there is an error after the initial handshake to the Oracle DB and further establishing a connection.
Check you oracle_cx for python and the oracle instant client whether the insta client is of the correct version to the DB. Try a connection form instantclient directly to the DB using sqlplus.
Reference:
django docs
DBA forum
django community
I have a python web application, where in, the application connects to a remote database.
Application: flask+uwsgi+nginx .
Database :mysql (remote).
The application exposes rest api for which data is served from remote database.
Everyday after db restoration, mysql service is restarted in the remote database. The connection between my application and remote database breaks, and it starts throwing error message
MySQL server has gone away.
until I manually restart the uwsgi service in my application
sudo service uwsgi restart
The duration between mysql service restart in remote db and uwsgi service restart in my system is the downtime.
Can my application re establish connection as soon as the mysql services are restarted ?
Please suggest any solutions?
It really depends on the way you connect to your database
In case you're using the popular ORMs:
SQLAlchemy ORM
engine = create_engine('mysql+mysqldb://...', pool_recycle=3600)
as stated in the documentation here
Peewee
#app.before_request
def _db_connect():
database.connect()
#app.teardown_request
def _db_close(exc):
if not database.is_closed():
database.close()
as stated in the documentation here
The issue is explained in depth in the mysql documentation here