[Tutor] For loop question

STREET Gideon (SPARQ) Gideon.STREET at ergon.com.au
Wed May 10 08:37:58 CEST 2006


Hi all,

Been trying to understand why the following doesn't work:

HostFile = open("hosts.txt", 'r')
host = HostFile.readlines()

for item in host:
    print "Connecting to device",item
    tn = telnetlib.Telnet(item)
...
Do some other stuff here
...

I get the following error:

Traceback (most recent call last):
  File "testtelnet.py", line 14, in ?
    tn = telnetlib.Telnet(item)
  File "c:\gideon\python24\lib\telnetlib.py", line 208, in __init__
    self.open(host, port)
  File "c:\gideon\python24\lib\telnetlib.py", line 225, in open
    for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
socket.gaierror: (11001, 'getaddrinfo failed')

The hosts.txt file contains device names on separate lines.  If I remove
the tn = .... Line the for loop iterates as I expect it to.  Can't
understand why I can't pass "item" as a string to the telnetlib.Telnet
command.

Cheers

Gideon

This e-mail (including any attachments) may contain confidential or
privileged information and is intended for the sole use of the person(s) to
whom it is addressed. If you are not the intended recipient, or the person
responsible for delivering this message to the intended recipient, please
notify the sender of the message or send an e-mail to
mailto:help.desk at ergon.com.au immediately, and delete all copies. Any
unauthorised review, use, alteration, disclosure or distribution of this
e-mail by an unintended recipient is prohibited. Ergon Energy accepts no
responsibility for the content of any e-mail sent by an employee which is of
a personal nature.

Ergon Energy Corporation Limited      ABN 50 087 646 062
Ergon Energy Pty Ltd      ABN 66 078 875 902


More information about the Tutor mailing list