Errors while installing apache bloodbound - python

after this command line :
python bloodhound_setup.py --environments_directory=/opt/bloodhound/environments bloodbound=DEF
I get this
Error: TimeoutError: Unable to get database connection within 0 seconds. (OperationalError: could not connect to server: Connection refused
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
)
Any help ?
thanks

Related

Python connection to server at "localhost" (::1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connect

try to crawl but something wrong with the host
import psycopg2
import geopandas as gpd
with psycopg2.connect(database="osm_data_science_db",user="postgres",
password='password',host='localhost') as connection:
gdf = gpd.GeoDataFrama.from_postgis("""SELECT*FROM osm_amenities_areas""", connection, geom_col='geom')
gdf[['osm_id','state','geom','post']].head()`

Does anyone know how to connect a PostgreSQL database to a Datalore notebook?

I'm working in Datalore (a jupyter notebook IDE) and I'm trying to connect to a postgresql (version 14) table via the following line of code.
df = pd.read_sql_table('emp','postgresql://{username}:{password}#localhost:5432/postgres')
where username and password are supplied in my notebook.
This gives the following error message:
OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused Is the server running on that host and accepting TCP/IP connections? connection to server at "localhost" (::1), port 5432 failed: Cannot assign requested address Is the server running on that host and accepting TCP/IP connections? (Background on this error at: https://sqlalche.me/e/14/e3q8)
When trying to test the connection to my database from the Datalore side pane, I get the following error message:
Connection to localhost:5432 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
I have already altered the IP address in pg_hba.conf from 127.0.0.0/32 to 0.0.0.0/0. Additionally, I have checked postgresql.conf and the listen_addresses = '*'.
My thoughts are that localhost shouldn't be used or that postmaster needs to be reset. If I am correct:
What should be used instead of localhost, and where do I find the correct hostname
How do I reset postmaster (I manually installed postgresql, I did not use Homebrew).
Is there anything else I haven't considered?

How to connect telnet to particular port of host?

I have HOST='xx.xxx.xx.xx' and PORT = xxxx
I tried                    
tn = telnetlib.Telnet(HOST, port=PORT, timeout=5)
I'm getting this error
ConnectionRefusedError: [Errno 61] Connection refused
Is there any other way to telnet to port other than default one?
ConnectionRefused means that the Server refused your connection, which in-turn could mean that telnet service is not running on that port. You can do telnet to any port only as long as the telnet service in running on that port in the server.

Connecting to PostgreSQL database through Python code

I have a Ubuntu virtual machine using Vagrant, I set it up and run it using vagrant up and vagrant ssh and I create the database psql -d dbname -f somesqlqueries.sql.
Whenever I try to connect to this database through python by doing conn = psycopg2.connect("dbname=dbname") I get this error:
psycopg2.OperationalError: could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Looking at solutions for this issue I changed postgresql.conf to have listen_address = '*' and still the same error occurs.
Also tried to turn off the firewall and run sudo ufw allow 5432/tcp and the error still persistent.

Heroku refuses connection to postgres database

I am trying to deploy my Flask app based on PostgreSQL on Heroku, but I when I try to create the table with db.create_all() I keep getting this error:
(psycopg2.OperationalError) could not connect t
rver: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
Here is how my code looks like:
app=Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']='postgres://kfgriimpfjecsv:Bk1*****G#localhost:5432/dd71doth8gopgh'
db=SQLAlchemy(app)
if __name__ == '__main__':
app.debug=True
app.run()
I am using Heroku Toolbelt to communicate with Heroku servers. Also, when I try this:
psql -p 5432 -h localhost
I get almost the same error:
psql: could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I also tried ec2-23-21-215-184.compute-1.amazonaws.com instead of localhost in the URI, but got the same error.
And here is the complete traceback that I get when I run db.create_all():
Any idea why the connection is being refused and how to solve this?
It seems I had to append a sslmode parameter to the database URI, so changing the second line to the following solved the problem:
app.config['SQLALCHEMY_DATABASE_URI']= "postgresql+psycopg2://kfgriimpfjecsv:Bk1*******G#ec2-23-21-215-184.compute-1.amazonaws.com:5432/dd71doth8gopgh?sslmode=require"

Categories