Reputation: 1323
The problem is, my script won't work (it's printing empty lane), but it works in python interactive console.
import telnetlib
tn = telnetlib.Telnet("killermud.pl", 4000)
data = tn.read_very_eager()
data = data.decode()
print(data)
tn.close()
What is the reason of such behavior?
Upvotes: 0
Views: 925
Reputation: 77
According to tlnetlib documentation, Telnet.read_very_eager() Raises EOFError if connection closed and no cooked data available. Return '' if no cooked data available otherwise. Do not block unless in the midst of an IAC sequence. If you do data=="", returns true, Therefore, it means that no cooked data is available
Upvotes: 0
Reputation: 312370
I just took a look at the documentation for the read_very_eager
method, which says:
Read all data available already queued or on the socket, without blocking.
It is likely that at the time you call this method that there is no data "already available or queued on the socket", so you're getting nothing back. You probably want to use something like the read_until
method, which will read data until it finds a specific string. For example:
data = tn.read_until('Podaj swoje imie')
Upvotes: 2