How to connect telnet to particular port of host? - python

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.

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?

Can't connect to SMTP server from Windows 7 VPS

I am trying to connect to gmails's smtp server and send email. But unfortunately, I am getting the below error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I have check the script in my local computer and it works. But it doesn't work on VPS. Using the below code to connect to server:
import smtplib, ssl
context = ssl.create_default_context()
with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=context) as smtp_server:
smtp_server.login(username, password)

Errors while installing apache bloodbound

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

Connection Error while connecting to PostgreSQL as postgres user?

I am not able connect to PostgreSQL remotely using python and psycopg2:
Here is my code.
>>> import psycopg2
>>> conn_string = "host='localhost' dbname='mydb' user='postgres'"
>>> print "Connecting to database\n ->%s" % (conn_string)
Connecting to database
->host='localhost' dbname='mydb' user='postgres'
>>> conn = psycopg2.connect(conn_string)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/tools/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.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?
The password is not set for postgres user.
Generally, I can connect to database by running following method on host.
1. SSH to box
2. su - postgres
3. psql
4. \c mydb
The server runs PostgreSQL 9.1.
You're trying to connect to PostgreSQL on localhost using a script running on your computer, but there's no PostgreSQL server running there.
For this to work, you'd have to ssh to the remote server, then run your Python script there, where the PostgreSQL server is "local" relative to the Python script.
(That's why running psql works - because you're running it on the remote server, where PostgreSQL is "local" relative to psql).
Alternately, you could:
Use an SSH tunnel to forward the PostgreSQL port from the local computer to the remote one; or
Connect directly over TCP/IP to the remote PostgreSQL server using its host name or IP address, after enabling remote connections on the server.
Note that just putting the server's IP address or host name into the connection string instead of localhost will not work unless you also configure the server to accept remote connections. You must set listen_addresses to listen for non-local connections, add any required firewall rules, set pg_hba.conf to permit connections from remote machines, and preferably set up SSL. All this is covered in the Client Authentication chapter of the PostgreSQL user manual.
You'll probably find an SSH tunnel simpler and easier to understand.

Categories