SSH via python (paramiko) error: "'_EllipticCurvePublicKey' object has no attribute 'verify'" - python

I am trying to connect to a SSH server using the python library paramiko.
The same code worked on the same computer before, but it started to show a warning when trying to connect. I can connect to the SSH server using the same computer and same users via terminal. The python code also works on other computers connected to the same LAN network.
I also tried to restart both pcs and reinstall paramiko with no success.
Following is the code and the warning message presented.
class SSH:
def __init__(self, ip):
self.ssh = SSHClient()
self.ssh.load_system_host_keys()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
self.ssh.connect(hostname=ip ,username='urs',password='pass')
Warning message:
Unknown exception: '_EllipticCurvePublicKey' object has no attribute 'verify'
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1886, in run
self.kex_engine.parse_next(ptype, m)
File "/usr/local/lib/python3.5/dist-packages/paramiko/kex_ecdh_nist.py", line 47, in parse_next
return self._parse_kexecdh_reply(m)
File "/usr/local/lib/python3.5/dist-packages/paramiko/kex_ecdh_nist.py", line 105, in _parse_kexecdh_reply
self.transport._verify_key(K_S, sig)
File "/usr/local/lib/python3.5/dist-packages/paramiko/transport.py", line 1748, in _verify_key
if not key.verify_ssh_sig(self.H, Message(sig)):
File "/usr/local/lib/python3.5/dist-packages/paramiko/ecdsakey.py", line 216, in verify_ssh_sig
self.verifying_key.verify(
AttributeError: '_EllipticCurvePublicKey' object has no attribute 'verify'
Do anybody have a suggestion about where the problem might be?
I tried to google and looked for the error here,but couldn't find it anywhere.
Thanks in advance!

I had the exact same error as now. I encountered this error with paramiko version 2.3.0. I downgraded to 2.1.2 and the operation i was doing proceeded normally.

Related

Python telnet connection abruptly ends

I'm currently working on a programme to automate some function for router configuration and I've managed to create a loopback interface between GNS3 and my computer so that I can connect python via telnet.
At first, the code ran smoothly and I had no problem, but when I switched to another router, it works only for a few commands and then it suddenly stops and I can't figure why.
This is the error I get:
Traceback (most recent call last):
File "C:\Licenta - program\test1\main.py", line 147, in <module>
tn.write(b"ip add ")
File "C:\Users\carme\AppData\Local\Programs\Python\Python39\lib\telnetlib.py", line 292, in write
self.sock.sendall(buffer)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
Any suggestions are welcomed!
Thank you!

Stuck with a MySQLdb SSL connection error in Python2.7

I have to maintain an old website built using Python2.7 that needs to continue working until we've finished creating a completely new version with more modern tools. Now this old website needs access to a remote MySQL database (connection is set up and working correctly), which so far has worked using the following:
import MySQLdb
db = MySQLdb.connect(host=Host,user=User,passwd=Pass,db=DBse)
Now the server has been upgraded from Ubuntu 18.04. to Ubuntu 20.04., and while I managed to install pip and MySQLdb for Python2.7, I now get the following error for the lines above:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2026, 'SSL connection error: unknown error number')
The SSL connection works fine in Python3 or directly from the command line.
Is there anything I can do to make this work?
Locate and add the line skip_ssl in /etc/mysql/my.cnf ( have tried this on MySQL 8.0.29 , Ubuntu 18)
This was the only thing that worked for me.
[mysqld]
skip_ssl

Unable to run Django Test Server in Ubuntu Server 16.04

I have 2 servers. I am attempting to setup one for continuous integration for my main website server
Web server 1(cloud-hosting):
Python3.6
Django3.1
Ubuntu16.04
Webserver 2(VPS):
Python3.7
Django3.1
Ubuntu16.04
Jenkins
--ShiningPanda(plugin)
Im new to web development, so if it seems odd as far as my web server types, that is why. I have been following along in the book Test Driven Development with Python. My issue is that when running python manage.py test [app] My [app] inherits from the class StaticLiveSever to generate a testing environment. On webserver 1, this works fine. On webserver 2, i get an error that the request address cannot be assigned. I use jenkins to build the environment, but the error i get is OSerror[99]:cannot assign requested address. I dont understand why this is happening when i run the same commands in Web Sever 1. It runs fine. Although again, the commands are run by jenkins and jenkins is configured to run python3.7
Full Traceback(Main Issue)
Traceback (most recent call last):
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/test/testcases.py", line 1449, in setUpClass
raise cls.server_thread.error
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/test/testcases.py", line 1374, in run
self.httpd = self._create_server()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/test/testcases.py", line 1389, in _create_server
return ThreadedWSGIServer((self.host, self.port), QuietWSGIRequestHandler, allow_reuse_address=False)
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 67, in __init__
super().__init__(*args, **kwargs)
File "/usr/lib/python3.7/socketserver.py", line 452, in __init__
self.server_bind()
File "/usr/lib/python3.7/wsgiref/simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "/usr/lib/python3.7/http/server.py", line 137, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
OSError: [Errno 99] Cannot assign requested address
After hardcoded host
Traceback (most recent call last):
File "/var/lib/jenkins/workspace/Superlists/functional_tests/base.py", line 47, in setUp
self.browser = webdriver.Firefox()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 100, in start
self.assert_process_still_running()
File "/var/lib/jenkins/shiningpanda/jobs/ddc1aed1/virtualenvs/d41d8cd9/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 113, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 69
geckodriver.log w/ hardcoded host ip in LiveTestServer
eckodriver: error: Address not available (os error 99)
geckodriver 0.27.0 (7b8c4f32cdde 2020-07-28 18:16 +0000)
WebDriver implementation for Firefox
USAGE:
geckodriver [FLAGS] [OPTIONS]
[...]
Hopefully the tracebacks above are not too confusing. Ultmiately what i did notice was the when im in webserver 2, i access the Django testcases.py module that has LiverServerThread and hardcode host=0.0.0.0 instead of host=localhost (1st traceback). The connection is then made although then the problem lies with geckodriver and the same thing (2nd traceback). I need to hard code ip 0.0.0.0 to be able to establish a connection, but then geckodriver is just listening, which i am assuming, at a completely different location (no error.log shown here).
So 1st id like to at least be able to make a connection to run the LiveServerThread class properly. Then try and resolve the issue with geckodriver. I also was not sure if the type of servers im running on poses as the problem.

Paramiko SSHClient.connect(...) fails when packaged with Pyinstaller on Windows

Paramiko's SSHClient.connect(...) method will raise an exception when packaged with Pyinstaller, but will run fine when not packaged.
This occurs using both of the Pyinstaller flags, --onedir and --onefile. I have tried Pyinstaller versions 3.5 and the current latest dev version, 4.0.dev0+ce887b462. --noupx does not have a noticeable effect.
My Paramiko version is 2.6.0.
My current Python version is 2.7.15
My OS is Windows 10 Pro, Version 10.0.17134, Build 17134.
This issue seems to result from Paramiko calling a C function in kernel32.dll, which unexpectedly returns null only when packaged.
Minimal example:
import paramiko
# The nature of this issue unfortunately requires
# a server that responds to SSH connections to test
host = None # Put a valid hostname here
port = 22 # Put a valid port here
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(
hostname=host,
port=port,
username=None,
password=None,
timeout=5
)
I expect the Pyinstaller-packaged version to run exactly the same as the unpackaged version -- in this case, to initiate a SSH connection, then fail with an AuthenticationException, since username and password are None:
> virtualenv venv
> venv\Scripts\activate.bat
> pip install pyinstaller==3.5 paramiko==2.6.0
[output truncated for brevity]
> pyinstaller minimal-paramiko-example.py
[output truncated for brevity]
> dist\minimal-paramiko-example\minimal-paramiko-example.exe
Traceback (most recent call last):
File "minimal-paramiko-example.py", line 16, in <module>
timeout=5
File "site-packages\paramiko\client.py", line 446, in connect
File "site-packages\paramiko\client.py", line 691, in _auth
File "site-packages\paramiko\agent.py", line 379, in __init__
File "site-packages\paramiko\agent.py", line 65, in _connect
File "site-packages\paramiko\agent.py", line 82, in _send_message
File "site-packages\paramiko\win_pageant.py", line 129, in send
File "site-packages\paramiko\win_pageant.py", line 96, in _query_pageant
File "site-packages\paramiko\_winapi.py", line 179, in write
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
[16768] Failed to execute script minimal-paramiko-example
> python minimal-paramiko-example.py # Will result in an AuthenticationException, since username and password are None; this is expected and normal
[output truncated for brevity]
This issue is caused by an interaction with PuTTY Pageant. Closing PuTTY Pageant causes this error to not occur. For some reason, it only manifests in the corner case of:
Using Pyinstaller
Running PuTTY Pageant
Failing to satisfy both requirements will not trigger the issue.

Problem with the ipy.vim script

I'm trying to use the ipy.vim script to set up a small python dev environment, but I'm running into a connection problem. When I type ipy_vimserver.setup("demo") I get this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 532, in __bootstrap_inner
self.run()
File "/usr/lib/pymodules/python2.6/IPython/Extensions/ipy_vimserver.py", line 109, in serve_me
self.listen()
File "/usr/lib/pymodules/python2.6/IPython/Extensions/ipy_vimserver.py", line 93, in listen
self.socket.bind(self.__sname)
File "<string>", line 1, in bind
error: [Errno 98] Address already in use
When I type it a second time, everything is fine but when I launch gvim the F4/F5 command do nothing and state that they can't connect to the Ipython server.
any suggestion?
Problem:
Look at the last line of the stack trace: error: [Errno 98] Address already in use
Explanation:
A nice explanation of "Address already in use" error can be found here: "Bind: Address Already in Use"
Possible Solution:
As I have not tried ipy.vim setup myself, from networking point of view, a quick suggestion would be to:
close/kill both the server (ipython server) and the client (vim running ipy.vim).
Restart ipython server
Run vim with ipy.vim and try to debug.
Additional Info:
On Linux/Unix machines, the timeout values are defined in /proc/sys/net/ipv4/tcp_keepalive_time and /proc/sys/net/ipv4/tcp_fin_time
On Windows machines, this is set in HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\TcpTimedWaitDelay. More details is here: TcpTimedWaitDelay
If I run the exact same code I get the same error. If I change the name from "demo" to, for example, "cookies" it works. Hmm....
This happens when there's already a socket with the name you're trying to create, in this case 'demo'. You need to delete it before doing the ipy_vimserver.setup - in your case, the socket file to delete is ~/.ipython/demo
(I'm one of the authors of ipy.vim)

Categories