Python3 ncclient/paramiko连接Cisco Nexus报错:_RSAPublicKey无verify属性
Hey DanM, this is a common compatibility issue I’ve seen pop up with older Ubuntu environments and Python NETCONF libraries—let’s work through fixing it step by step.
Root Cause
The AttributeError: '_RSAPublicKey' object has no attribute 'verify' error almost always comes down to incompatible versions of the cryptography library. Ubuntu 16.04 LTS ships with an outdated cryptography version (usually around 1.2.3), while newer releases of ncclient (the Python library handling NETCONF connections) rely on updated cryptography APIs that changed how RSA public key verification works.
Step-by-Step Fix
Check your current
cryptographyversion
Run this command to confirm which version you have installed:pip3 show cryptographyIf the version is older than 2.5, that’s definitely the culprit here.
Upgrade
cryptographyto a compatible stable version
Ubuntu 16.04’s Python 3.5 doesn’t support the latestcryptographyreleases, so install a version that plays nice with both your system andncclient:pip3 install --user --upgrade cryptography==3.4.8The
--userflag installs the package to your personal user directory, avoiding permission issues with system-level packages.Update
ncclientto a matching compatible version
Pair the upgradedcryptographywith a stablencclientrelease that supports it:pip3 install --user --upgrade ncclient==0.6.13Test your connection code
Modify your existing code to run a basic test (adjust credentials and device IP as needed):from ncclient import manager def connect_to_nexus(): try: with manager.connect( host="192.168.1.100", # Replace with your Nexus device IP port=830, username="admin", password="your-secure-password", hostkey_verify=False, # Disable only for testing; enable in production device_params={'name': 'nexus'} ) as session: print("Connection successful!") # Example: Fetch running configuration config = session.get_config(source='running') print(config) except Exception as e: print(f"Connection failed: {str(e)}") connect_to_nexus()Note: Disabling
hostkey_verifyis for testing purposes only—for production use, make sure you have the device’s host key properly configured.
If you still hit snags, double-check that you’re using the correct Python 3 environment (run which python3 to confirm) and that no system-level packages are overriding your user-installed libraries.
内容的提问来源于stack exchange,提问作者DanM

