Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

utilities.get_template_dir() unexpected keyword argument 'package' #3527

Closed
dakotah-hurda opened this issue Nov 7, 2024 · 5 comments
Closed

Comments

@dakotah-hurda
Copy link

dakotah-hurda commented Nov 7, 2024

Description of Issue/Question

I am running a simple SSH script with Netmiko v4.4.0 on Python 3.13.0. The issue only appears when using the 'use_textfsm=True' argument in the send_command() function.

It appears the function ultimately calls the netmiko.utilities.get_template_dir() function on line 298.

On line this code section, two arguments are passed into the function: 'package' and 'resource':

else:
with pkg_resources.path(
package="ntc_templates", resource="parse.py"
) as posix_path:
# Example: /opt/venv/netmiko/lib/python3.9/site-packages/ntc_templates/templates
template_dir = str(posix_path.parent.joinpath("templates"))
# This is for Netmiko automated testing
if _skip_ntc_package:
raise ModuleNotFoundError()

The traceback I'm experiencing indicates the pkg_resources.path() function being called does not expect those two arguments.

Setup

Netmiko version

netmiko       4.4.0
python         3.13.0

Netmiko device_type (if relevant to the issue)

cisco_ios

Steps to Reproduce the Issue

  1. Create new python venv with python -m venv dirname (python 3.13.0)
  2. Install netmiko with pip install netmiko
  3. Write and execute the python script shown below, being sure to enable text_fsm in the send_command() function.

Error Traceback

Traceback (most recent call last):
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\test.py", line 20, in <module>
    output = c.send_command('show ip arp', use_textfsm=True)
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\Lib\site-packages\netmiko\base_connection.py", line 111, in wrapper_decorator
    return_val = func(self, *args, **kwargs)
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\Lib\site-packages\netmiko\utilities.py", line 596, in wrapper_decorator
    return func(self, *args, **kwargs)
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\Lib\site-packages\netmiko\base_connection.py", line 1834, in send_command
    return_val = structured_data_converter(
        command=command_string,
    ...<6 lines>...
        ttp_template=ttp_template,
    )
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\Lib\site-packages\netmiko\utilities.py", line 560, in structured_data_converter
    structured_output_tfsm = get_structured_data_textfsm(
        raw_data, platform=platform, command=command, template=textfsm_template
    )
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\Lib\site-packages\netmiko\utilities.py", line 377, in get_structured_data_textfsm
    template_dir = get_template_dir()
  File "C:\Users\dakotah.hurda\repos\netmiko-testing\Lib\site-packages\netmiko\utilities.py", line 298, in get_template_dir
    with pkg_resources.path(
         ~~~~~~~~~~~~~~~~~~^
        package="ntc_templates", resource="parse.py"
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ) as posix_path:
    ^
TypeError: path() got an unexpected keyword argument 'package'

Relevant Python code

from netmiko import ConnectHandler

conn_data = {
    'device_type': 'cisco_ios',
    'host':   'dvc_name',
    'username': 'myusername',
    'password': 'mypassword',
}

c = ConnectHandler(**conn_data)
output = c.send_command('show ip arp', use_textfsm=True)

print(output)
@dakotah-hurda
Copy link
Author

Just realized there's an open issue for packages support open, is this related?

#3520

@ktbyers
Copy link
Owner

ktbyers commented Nov 7, 2024

@dakotah-hurda This should already be fixed in the develop branch. It is a PY3.13 change.

I need to do a release to pypi with Netmiko support for PY3.13, now that PY3.13 has been released.

@ktbyers ktbyers closed this as completed Nov 7, 2024
@ktbyers
Copy link
Owner

ktbyers commented Nov 7, 2024

Yes, same underling issue as #3520.

@dakotah-hurda
Copy link
Author

Awesome, thanks for the quick response, you rock! 🤘

Will temporarily downgrade to 3.12.x until the new release is out. Thanks!

@Tes3awy
Copy link

Tes3awy commented Nov 13, 2024

A workaround for this issue is to specify the textfsm_template keyword in the send_command. Something like:

from netmiko import ConnectHandler

...

conn = ConnectHandler(**device)
facts = conn.send_command(
        "show version",
        use_textfsm=True,
        textfsm_template="C:\\Path\\to\\Project\\.venv\\Lib\\site-packages\\ntc_templates\\templates\\cisco_ios_show_version.textfsm",
    )
conn.disconnect()

print(facts)
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants