Python Forum
Error f = open(r'D:\NetAuto\myswitches.txt') - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Networking (https://python-forum.io/forum-12.html)
+--- Thread: Error f = open(r'D:\NetAuto\myswitches.txt') (/thread-26087.html)



Error f = open(r'D:\NetAuto\myswitches.txt') - phutran - Apr-21-2020

Hi all,
This is my code:
import getpass
import sys
import telnetlib

user = raw_input("Enter your telnet username: ")
password = getpass.getpass()

f = open(r'D:\NetAuto\myswitches.txt')

for line in f:
	print "configuring Switch " + (line)
	HOST = line
	tn = telnetlib.Telnet(HOST)

tn.read_until("Username: ")
tn.write(user + "\n")
if password:
	tn.read_until("Password: ")
	tn.write(password + "\n")

tn.write("conf t\n")
	
for n in range(40,51):
	tn.write("vlan " + str(n) + "\n")
	tn.write("name Python_VLAN_" + str(n) + "\n")

	tn.write("end\n")
	tn.write("wr\n")
	tn.write("exit\n")
	
print tn.read_all()
But there are error for the code:
configuring Switch 192.168.1.101
Error:
Traceback (most recent call last): File "D:\NetAuto\Openfile.py", line 13, in <module> tn = telnetlib.Telnet(HOST) File "C:\Python27\lib\telnetlib.py", line 211, in __init__ self.open(host, port, timeout) File "C:\Python27\lib\telnetlib.py", line 227, in open self.sock = socket.create_connection((host, port), timeout) File "C:\Python27\lib\socket.py", line 557, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno 11001] getaddrinfo failed
Please help me this error