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

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)

Related

connection refused while using firebirdsql to connect localhost fdb file

I'm trying to read fdb files in Ubuntu using firebirdsql:
conn = firebirdsql.connect(host='localhost', database='db.fdb',
user='sysdba', password='masterkey', charset='utf8')
But while connecting, it just said Connection refused.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "~/.local/lib/python3.6/site-packages/firebirdsql/__init__.py", line 94, in connect
conn = Connection(**kwargs)
File "~/.local/lib/python3.6/site-packages/firebirdsql/fbcore.py", line 595, in __init__
self.sock = SocketStream(self.hostname, self.port, self.timeout, cloexec)
File "~/.local/lib/python3.6/site-packages/firebirdsql/socketstream.py", line 46, in __init__
self._sock = socket.create_connection((host, port), timeout)
File "/usr/lib/python3.6/socket.py", line 724, in create_connection
raise err
File "/usr/lib/python3.6/socket.py", line 713, in create_connection
sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused
the code works well on Windows Server, but on Ubuntu it can't establish the connection, how can I solve it?
In the comments you indicate you don't have a Firebird server installed on your machine. As there is no server listening on localhost port 3050, you get the connection refused error.
That firebirdsql, the driver you're using, is pure Python doesn't mean it can open database files by itself, it means it doesn't use a native library to establish a connection, but that it implements the Firebird TCP/IP wire protocol in Python. You will need a Firebird server (either localhost or remotely) to connect to.
Also: a server normally won't be able to access files in your home directory.

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

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.

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?

connection refused error in paho-mqtt python package

I am new to paho-mqtt. I was trying to publish a topic using my localhost and I encountered the following error :
Traceback (most recent call last):
File "server.py", line 10, in <module>
client1.connect(host,port,keepalive)
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 768, in connect
return self.reconnect()
File "/usr/local/lib/python2.7/dist-packages/paho_mqtt-1.3.1-py2.7.egg/paho/mqtt/client.py", line 895, in reconnect
sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
File "/usr/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 111] Connection refused
My python code is below :
import paho.mqtt.client as paho
port=1883
host = "localhost"
keepalive = 60
def on_publish(client,userdata,result):
print("data published \n")
pass
client1= paho.Client("control1")
client1.on_publish = on_publish
client1.connect(host,port,keepalive)
ret= client1.publish("Robot","Robot 1 move_left")
When I run the same code with iot.eclipse.org as host then it works fine. Any help would be highly appreciated.
I was facing the same issue.
The solution was to install a local MQTT broker.
http://www.steves-internet-guide.com/install-mosquitto-linux/
The exposed docker port for mqtt is usually different than 1883.
I use the official eclipse mosquitto docker and the run example on their page is something like:
sudo docker run -it -p 11883:1883 -p 9001:9001 eclipse-mosquitto
therefore the client should connect to port 11883
client.connect(broker_address, 11883)

Categories