I have remote Ubuntu server, and I'm trying set up remote debugging.
Configured as shown here.
import sys
import pydevd
sys.path.append('/root/home/scripts/pycharm-debug.egg')
pydevd.settrace('my_remote_server_IP', port=51234,
stdoutToServer=True, stderrToServer=True)
I also connect remote host for synchronizing and uploading my python scripts to remote server. (Tools -> Deployment -> ...)
When I start debugging:
C:\Python27\python.exe C:/Projects/python/demo.py
Could not connect to xx.xx.xx.166: 51234
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 2.7.1\helpers\pydev\pydevd_comm.py", line 428, in StartClient
s.connect((host, port))
File "C:\Python27\Lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 10061] ����������� �� �����������,
Process finished with exit code 1
How to solve this problem?
The first argument of pydevd.settrace function should be the host, where PyCharm is installed. Not remote server.
Also in most cases if you want to run and debug your code remotely it is more convenient to use remote interpreter feature.
I resolved this problem by changing the port.
Related
I want to transfer a file from a local server (that'll contain the code and file) to a remote server preferably using ssh. Here's the code:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('Servername', port = 135, username='username', password='password')
print "connected successfully!"
sftp = ssh.open_sftp()
print sftp
sftp.put('G:\TestDocument.txt','G:\TestDocument.txt' )
sftp.close()
print "copied successfully!"
ssh.close()
But I get this error:
No handlers could be found for logger "paramiko.transport"
Traceback (most recent call last): File
"C:/Python27/testtransfer.py", line 5, in
ssh.connect('Servername', port = 135, username='username', password='password') File
"C:\Python27\lib\site-packages\paramiko\client.py", line 392, in
connect
t.start_client(timeout=timeout) File "C:\Python27\lib\site-packages\paramiko\transport.py", line 545, in
start_client
raise e SSHException: Error reading SSH protocol banner
Can you tell me why am I receiving this error? I have purposely used port 135 because port 22 is closed on the target server and 135 (among others) is open.
You can even suggest some other way in which I can transfer files from one server to another using Python.
SSHException: Error reading SSH protocol banner
the error usually means the remote service was not a ssh service. try to make sure the service on port 135 is actually ssh.
And what's the OS on your server? Windows? if so you may need to setup a 3rd-part ssh server on your server. In my opinion if you need to copy files from windows to windows ftp is a much simpler solution. python has a built-in lib ftplib.
I wrote a generic script on Python that supports Windows and Unix ssh connection from Unix.
When I try Unix command from Unix to create dir in Windows, I get exit 53
/usr/bin/ssh2 --password pass -l admin ip_address mkdir "C:\Temp\ALEX_TEST_EX" &
When I write only /usr/bin/ssh2 --password pass -l admin ip_address, it is Ok. I login to Windows
When I try C:\Temp\ALEX_TEST_EX on this machine manually it is also Ok.
What is problem?
I also try to use with Python ssh2 command like
import paramiko
ssh = paramiko.SSHClient()
ssh.connect("ip_address", username="admin", password="pass")
but I get exceptions
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/python3.5/site-packages/paramiko/client.py", line 402, in connect
self, server_hostkey_name, server_key
File "/python3.5/site-packages/paramiko/client.py", line 768, in missing_host_key
'Server {!r} not found in known_hosts'.format(hostname)
paramiko.ssh_exception.SSHException: Server 'X.Y.Z.W' not found in known_hosts
You have not configued the client machine to allow you to know the server you are trying to connect to. You can either configure the client, or as a work around you can set the MissingHostKeyPolicy on paramiko like:
Code:
To warn when host not in known hosts:
ssh.set_missing_host_key_policy(paramiko.WarningPolicy)
To auto add host to know hosts:
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy)
Full Code:
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.WarningPolicy)
ssh.connect("localhost", username="admin", password="pass")
So, I have this program I made that connects to another computer (which is a linux machine) through SSH in python with the help of the library paramiko. I've made all the development on my ubuntu machine at work and it runs just fine on my home gentoo setup. I've been asked to make it work on a windows machine, and I get errors I cannot quite figure out what they mean to be honest, I'm not really confortable in windows environments.
The code is the following :
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(
hostname=self.address,
username=self.username,
password=self.password
)
self.shell = self.ssh.invoke_shell(width=self.shell_width, height=self.shell_height)
self.transport = paramiko.Transport((self.address, self.port))
self.transport.connect(
username=self.username,
password=self.password
)
self.sftp = paramiko.SFTPClient.from_transport(self.transport)
So basically I have an interactive SSH shell I use to issue commands, and an SFTP connection as well to retrieve the files I created from the SSH session.
When running this code on windows :
Traceback (most recent call last):
File "C:/Users/labor/PycharmProjects/OPSS/OPSS.py", line 9, in <module>
shell.run("uptime")
File "C:\Python27\lib\site-packages\spur\ssh.py", line 162, in run
return self.spawn(*args, **kwargs).wait_for_result()
File "C:\Python27\lib\site-packages\spur\ssh.py", line 173, in spawn
channel = self._get_ssh_transport().open_session()
File "C:\Python27\lib\site-packages\spur\ssh.py", line 251, in _get_ssh_transport
raise self._connection_error(error)
spur.ssh.ConnectionError: Error creating SSH connection
Original error: [Errno 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 don't really know what the system is trying to tell me when it says the party failed to respond because I can connect to it just fine with WinSCP and PuTTY from windows (which are the two programs I used to test both SSH and SFTP).
As you can tell I'm using PyCharm as my IDE, and I installed paramiko using its package manager on windows (on my linux machines I used pip).
Does anyone know what is happening ? And how can I make it work ? Thanks !
I have an error on a script I have wrote since few months, it worked very good with a raspberry pi, but now with an orange pi I have this:
>>> import paramiko
>>> transport = paramiko.Transport("192.168.2.2", 22)
>>> transport.connect(username = "orangepi", password = "my_pass")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 978, in connect
self.start_client()
File "/usr/lib/python2.7/dist-packages/paramiko/transport.py", line 406, in start_client
raise e
paramiko.ssh_exception.SSHException: Incompatible ssh server (no acceptable macs)
I can connect in console with ssh without problem.
Somebody has an idea ?
You should check if any of those MACs algorithms are available on your SSH server (sshd_config, key: MACs) :
HMAC-SHA1
HMAC-MD5
HMAC-SHA1-96
HMAC-MD5-96.
They are needed in order for Paramiko to connect to your SSH server.
On your remote server, edit /etc/ssh/sshd_config and add a MACs line or append to the existing one, with one or more of hmac-sha1,hmac-md5,hmac-sha1-96,hmac-md5-96 (values are comma-separated), for example:
MACs hmac-sha1
Now restart sshd: sudo systemctl restart ssh.
If the above solutions do not work, you need to upgrade Paramiko as found out by this answer.
I'm currently attempting to setup a SiriServer (that's beside the point) on Xubuntu 12.10 x64, when I run the server python returns error
socket.error: [Errno 98] Address already in use.
The server by default is attempting to run on port 443, which unfortunetly is required in order for this application to work.
To double check if anything is running on port 443, I execute the following:
lsof -i :443
There's no results, unless I have something like Chrome or Firefox open, which I end up closing. Here's the full return from attempting to run the server application.
dustin#dustin-xubuntu:~/Applications/SiriServer$ sudo python siriServer.py
CRITICAL load_plugins Failed loading plugin due to missing module: 'Wordnik library not found. Please install wordnik library! e.g. sudo easy_install wordnik'
INFO <module> Starting Server
Traceback (most recent call last):
File "siriServer.py", line 493, in <module>
server = SiriServer('', options.port)
File "siriServer.py", line 425, in __init__
self.bind((host, port))
File "/usr/lib/python2.7/asyncore.py", line 342, in bind
return self.socket.bind(addr)
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
I'm stuck on what to do, as this is the last part of setting up this application. Any help is appreciated.
You're not root -- that's your problem. To bind to ports under 1024 on Unix, you must be the superuser. So, hit su and try the python code again. Alternatively, bind to a port from 1024 to 65535.
This often happens when a python program doesn't exit properly when pressing ^C or ^Z. You could try reseting the terminal or exiting the terminal. You can also do killall -9 server.py
Another effective way to help prevent this even if you have root privs this can happen if a socket is not closed properly, here is a fix:
s=socket.socket( )
s.bind(("0.0.0.0", 8080))
while 1:
try:
c, addr = s.accept()
except KeyBoardInterrupt:
s.close()
exit(0)
I got that error even if port number is more than 1024
You can use
pkill -9 python
run command twice, it will list all python files which are killed
List all processes that you have running with
ps -a
Take the PID corresponding to python and pipe it into the kill command with (Example PID 2770)
kill -9 2770