Why am I getting 'getaddrinfo failed' while connecting to remote server? - python

I am using the socket module in python to connect to a remote server at https://vedant-chatroom.glitch.me/chat.html?user=python. This is my code (test.py):
import socket
web_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
web_socket.connect(("https://vedant-chatroom.glitch.me/chat.html?user=python", 443))
After running I get:
Traceback (most recent call last):
File "test.py", line 4, in <module>
web_socket.connect(("https://vedant-chatroom.glitch.me/chat.html?user=python", 443))
socket.gaierror: [Errno 11001] getaddrinfo failed
The remote server is a Node based server which is using the sockets.io package and express.

Related

"[WinError 10061] No connection could be made because the target machine actively refused it" with python socket to Docker

I am running a Docker container on Windows which is basically made from Ubuntu Image with some add-ons(asterisk pbx). When I try to connect to it(I take IPv4 from ipconfig's "WSL") with python socket:
import socket
a = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
a.connect(('172.19.96.1', 5038))
I get
Traceback (most recent call last):
File "E:\Projects\project\test.py", line 43, in <module>
a.connect(('172.19.96.1', 5038))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
How do I connect to it? I am 100% sure my container is listening to 0.0.0.0:5038 as I can connect to it from inside of the container.
btw I tried to change '172.19.96.1' to '127.0.0.1' and 'localhost' both, but all the same I'm getting that error.

Getting error : ConnectionRefusedError: [Errno 111] Connection refused

I am trying to run this on Ubuntu
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("10.0.2.15", 5555)) #10.0.2.15 is the Kali IP
s.send("Connected!\n")
data_received = s.recv(1024)
print(data_received)
s.close()
While running
‐v ‐l ‐p 5555 this on kali
But i keep getting this error:
Traceback (most recent call last):
File "client.py", line 4, in <module>
s.connect(("10.0.2.15", 4444))
ConnectionRefusedError: [Errno 111] Connection refused

PYTHON: Connection check with socket and VM

i have a local machine IP: 192.168.1.150 and a VM IP:192.168.1.152.
I'd like to check if the connection exists with my ubuntu server (by the way my ubuntu server is installed on the VM) or not:
My Code:
#!/usr/bin/env python3
import os
import sys
import socket
SERVER_IP = '192.168.152'
SERVER_PORT = 80
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((SERVER_IP, SERVER_PORT))
print('Connected')
s.close()
but sadly it doen't work and i get the ERROR:
Traceback (most recent call last):
File "./checkConnectionToServer.py", line 11, in <module>
s.bind((SERVER_IP, SERVER_PORT))
PermissionError: [Errno 13] Permission denied

Connection refused when trying to create a connection

We are using django to call APIs (ubuntu server) that are on 172.20.44.148.
Our code is the following:
import socket
socket.create_connection(('172.20.44.148', 8080), timeout=2)
However, the connection refused.
This is the error we got from apache:
[root#xxx ~]# python /home/something.py
Traceback (most recent call last):
File "/home/something.py", line 3, in <module>
socket.create_connection(('172.20.44.148', 8080), timeout=2)
File "/usr/local/lib/python2.7/socket.py", line 571, in create_connection
raise err
socket.error: [Errno 111] Connection refused
We also tried to ping 172.20.44.148 and we got a response.
Any ideas?

python paramiko socket.error: [Errno 113] No route to host

I can't connect to my host with paramiko. It's no problem to connect throgh a shell though.
My code:
import socket
from paramiko import client
ssh=client.SSHClient()
ssh.load_system_host_keys()
host=socket.gethostbyname("rumo.fritz.box") # works -> host exists
print host
ssh.connect(host,2012,"sshad","MyPassword",timeout=10)
stdin,stdout,stderr=ssh.exec_command("ls -la")
ssh.close()
The error+output:
192.168.178.37
Traceback (most recent call last):
File "./rumo_suspend.py", line 20, in <module>
ssh.connect(host,2012,"sshad","MyPassword",timeout=10)
File "/usr/lib/python2.7/dist-packages/paramiko/client.py", line 296, in connect
sock.connect(addr)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 113] No route to host
Connecting through a shell:
ssh -p 2012 sshad#rumo.fritz.box
sshad#rumo.fritz.box's password:
Welcome to Linux Mint 17.2 Rafaela (GNU/Linux 3.16.0-031600-generic x86_64)

Categories