Reputation: 49
I am trying to connect to an Apache AGE database using Python and am getting a “connection refused” error. How can I resolve this?
I have installed Apache AGE and Python on my local machine. In my Python script, I'm using the psycopg2 library to connect to the database using the following code:
import psycopg2
conn = psycopg2.connect(
host="localhost",
port=5433,
database="mydatabase",
user="myuser",
password="mypassword"
)
I expected this code to establish a connection to the Apache AGE server and allow me to query the database.
Instead, I'm getting a 'connection refused' error message when running the code.
Upvotes: 1
Views: 1047
Reputation: 51
check the specific issue. if it is the server not running, syntax or logical error maybe. Add error-handling print in this code to check what might be the specific error in your code as shown in the image below.
Upvotes: 0
Reputation: 1
Make sure you have Python 3.9 on your system. If not, you can follow this guide to upgrade to 3.9. Then download the Apache AGE python Driver using the command.
pip install apache-age-python
Lastly, check your PostgreSQL version. Currently PostgreSQL 11,12 and 13 are compatible with AGE. If you have any other version, upgrade PostgreSQL to any of these versions. For this, you can follow this blog post.
Upvotes: 0
Reputation: 9
If you haven’t updated to Python (3.9). After that, make sure you have the correct and compatible version of AGE installed with your PostgreSQL. After that, make sure your PostgreSQL server is running before you try to establish the connection.
Also check for AGE Python drivers.
pip install apache-age-python
Upvotes: 0
Reputation: 1
You need to verify that PostgreSQL is running on your local machine. Secondly, make sure that you have a Python version not earlier than 3.9 installed on your system.
If both conditions are satisfied, you could refer to this sample for reference.
Upvotes: 0
Reputation: 42
Install these prerequisites
sudo apt-get update
sudo apt-get install python3-dev libpq-dev
git clone https://github.com/apache/age.git
cd age/drivers/python
Install required packages using the following command
pip install -r requirements.txt
Make sure that AGE is loaded on your PostgreSQL server, and run the following command:
# psql
CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;
Some examples of using Python drive:
Ref: age/drivers/python/ (GitHub)
Upvotes: 1
Reputation: 105
First of all, make sure your PostgreSQL server is running (you can access it from the console) and you have created a database from the console with a specific user. You can see the guides for installing Apache AGE.
Now, as you know you have the correct setup for accessing Apache AGE, You need to make sure your have Python 3.9 or greater installed in your system.
Install this Python package by pip install apache-age-python
Use the proper database name, user name and password in the following code
import psycopg2
import age
GRAPH_NAME = "test_graph"
conn = psycopg2.connect(
host="172.17.0.2",
port="5432",
dbname="postgres",
user="postgres",
password="agens"
)
age.setUpAge(conn, GRAPH_NAME)
Upvotes: 1
Reputation: 1
First make sure you have Python 3.9 or later as this is the requirement of the Apache AGE Python driver.
Then, check if you have Apache AGE Python driver installed. If not, use the following command to install from PyPi:
pip install apache-age-python
Upvotes: 0
Reputation: 34
This issue occurs when client is unable to establish a connection to a server, on the specified host and port. DO the following checks and See if it works 1 Check if Apache Age is running 2 Verify the port number 3 Check for firewall or security software 4 Verify the hostname
Upvotes: 0