2

I am trying to connect to an Apache Age database using Python and 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.

Prachi
  • 39
  • 3

9 Answers9

1
  1. First of all make sure your postgres server is running (you can access it from console) and you have created a database from console with with specific user. You can see the guides for installing apache age.

  2. Now, as you know you have correct setup for accessing apache age, You need to make sure your have Python 3.9 or greater installed in your system.

  3. Install this python package by pip install apache-age-python

  4. 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)
  1. You can see the sample to get to know more about how to use the package
1

install these prerequisites

  • over Python 3.9
  • This module runs on psycopg2 and antlr4-python3
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 loaded on your PostgreSQL, run the following command

# psql 
CREATE EXTENSION age;
LOAD 'age';
SET search_path = ag_catalog, "$user", public;

Some examples of using python drive:

Ref: https://github.com/apache/age/tree/master/drivers/python

0

First Make sure you have over Python 3.9 as this is requirement of 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 .

.

0

Are you sure the correct version of Python (3.9) is installed? If so, make sure you have a valid postgres connection.

tokamak32
  • 27
  • 7
0

You need to verify that postgres is running on your local machine, secondly make sure that you have python version not earlier than 3.9 installed on your system. If both conditions are satisfied, you could refer to this sample for reference.

0

if you havent update to python (3.9). After that make sure you have the correct and compaible version of AGE install with your postgreSQL. After that make sure your postgreSQL server is running before you try to establish the connection. Also check fro AGE python drivers.

pip install apache-age-python
0

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 Postgres 11,12 and 13 are compatible with AGE. If you have any other version upgrade PostgreSQL to any of this version. For this you can follow this blog.

0

Confirm that the installed version of python is 3.9 and above, and most importantly ensure that your postgres is running on localhost and on the said port.

Peter
  • 43
  • 4
0

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