'getting error TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
I am trying to use the python netmiko library to automate configuration of cisco devices using files, however I am getting the below error while testing. From googling I am guessing it may be something to do with the open function I have used for the configuration file.
Traceback (most recent call last):
File "config-auto.py", line 55, in <module>
device_list()
File "config-auto.py", line 50, in device_list
output = net_connect.send_config_from_file(inputfile)
File "/home/mmwanza/flask-project/venv/lib/python3.6/site-packages/netmiko/base_connection.py", line 2022, in send_config_from_file
with io.open(config_file, "rt", encoding="utf-8") as cfg_file:
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper
from netmiko import ConnectHandler
import getpass
#prompt user for username
username = input('Enter username: ')
##username method to return the username
def credentials_username():
cred = username
return cred
#prompt user for password
p = getpass.getpass('Enter password: ')
##password method to return the password
def credentials_password():
password = p
return password
#Prompt to enter device file
devices_file = input('Enter devices inventory file name: ')
with open(devices_file) as hosts:
addresses = hosts.readlines()
#Prompt to enter configuration file
configsfile = input('Enter configuration file: ')
inputfile = open(configsfile, "r")
##devices dictionary
def device_list():
ios_device_info = dict()
for device in addresses:
ios_device_info['ip'] = device
ios_device_info['device_type'] = "cisco_ios"
ios_device_info['username'] = credentials_username()
ios_device_info['password'] = credentials_password()
net_connect = ConnectHandler(**ios_device_info)
output = net_connect.send_config_from_file(inputfile)
device_list()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
