Installed netmiko in PyCharm but PyCharm failed to execute netmiko for SSH connection

Answered

Installed netmiko in PyCharm successfully, but when write code to import netmiko, it doesn't take effect. Meanwhile executing the code with iPhython, everything works fine. I did add netmiko path to PyCharm project interpreter to point to 'netmiko-cfg', 'netmiko-grep' and 'netmiko-show' but still my code can't be executed.

from getpass import getpass


my_device = {
'host':'10.1.51.122',
'username':'fractus-admin',
'password': getpass(),
'secret':getpass(),
'device_type':'cisco_nxos',
'global_delay_factor': 2,
}

net_connect = Netmiko(**my_device)

# delay time multiple by 2
output = net_connect.send_command("copy run start", delay_factor=2)
print(output)

net_connect.disconnect()

Code output:

 

Traceback (most recent call last):
File "/Users/Sean/Sites/project2/delay_factor.py", line 2, in <module>
from netmiko import ConnectHandler
File "/Users/Sean/Envs/project2/lib/python2.7/site-packages/netmiko/__init__.py", line 8, in <module>
from netmiko.ssh_dispatcher import ConnectHandler
File "/Users/Sean/Envs/project2/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 4, in <module>
from netmiko.a10 import A10SSH
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/netmiko/a10/__init__.py", line 2, in <module>
from netmiko.a10.a10_ssh import A10SSH
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/netmiko/a10/a10_ssh.py", line 4, in <module>
from netmiko.cisco_base_connection import CiscoSSHConnection
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/netmiko/cisco_base_connection.py", line 3, in <module>
from netmiko.base_connection import BaseConnection
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/netmiko/base_connection.py", line 13, in <module>
import paramiko
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/paramiko/__init__.py", line 22, in <module>
from paramiko.transport import SecurityOptions, Transport
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/paramiko/transport.py", line 37, in <module>
from paramiko import util
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/paramiko/util.py", line 32, in <module>
from paramiko.common import DEBUG, zero_byte, xffffffff, max_byte
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/paramiko/common.py", line 23, in <module>
from paramiko.py3compat import byte_chr, PY2, bytes_types, text_type, long
File "/Users/ABC/Envs/project2/lib/python2.7/site-packages/paramiko/py3compat.py", line 2, in <module>
import base64
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/base64.py", line 98, in <module>
_urlsafe_encode_translation = string.maketrans(b'+/', b'-_')
AttributeError: 'module' object has no attribute 'maketrans'

Process finished with exit code 1

 

 

5 comments
Comment actions Permalink

Hi Seanche,

I'm getting the same problem. I can't execute netmiko from Pycharm. Nevertheless, the same code is working if I execute it from Python console outside Pycharm.

Did you manage to get it fixed?

Thanks!

0
Comment actions Permalink

Hi, try to disable

  • Add content roots to PYTHONPATH
  • Add source roots to PYTHONPATH

options in the Run Configuration you are using to execute the code. It looks like you have a namespace collision due to a custom module/package called string.

0
Comment actions Permalink

Thanks for the answer, Pavel.

Unfortunately that didn't solved the problem. I'm still getting this errors when python execute netmiko ConnectHandler.

By the way, I've configured Pycharm to use the system interpreter in my linux machine.

These are the errors I'm getting:

Traceback (most recent call last):
  File "/home/amarcos/PycharmProjects/Testing2/cisco_connect.py", line 24, in <module>
    net_connect = netmiko.ConnectHandler(**device)
  File "/home/amarcos/.local/lib/python2.7/site-packages/netmiko/ssh_dispatcher.py", line 190, in ConnectHandler
    return ConnectionClass(*args, **kwargs)
  File "/home/amarcos/.local/lib/python2.7/site-packages/netmiko/base_connection.py", line 245, in __init__
    self.establish_connection()
  File "/home/amarcos/.local/lib/python2.7/site-packages/netmiko/base_connection.py", line 743, in establish_connection
    raise NetMikoTimeoutException(msg)
netmiko.ssh_exception.NetMikoTimeoutException: Connection to device timed-out: cisco_ios 10.20.128.1:22

Process finished with exit code 1

 

Thanks!

0
Comment actions Permalink

This is a different error than in the original case, you have another problem.

>Nevertheless, the same code is working if I execute it from Python console outside Pycharm

Make sure you use the same interpreter in PyCharm and in the console outside of it. At the moment it looks like a netmiko problem (https://github.com/ktbyers/netmiko/issues/445) not a PyCharm bug.

0
Comment actions Permalink

Click the help icon and it should give you the option to install netmiko

0

Please sign in to leave a comment.