This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: telnetlib Telnet.interact fails on Windows but not Linux
Type: behavior Stage: resolved
Components: Library (Lib), Windows Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jackdied Nosy List: BreamoreBoy, brian.curtin, ezio.melotti, jackdied, mnewman, r.david.murray, skrah
Priority: normal Keywords: patch

Created on 2010-01-23 02:14 by mnewman, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
telnetlib_windows.patch r.david.murray, 2010-10-23 14:16
Messages (10)
msg98174 - (view) Author: Michael Newman (mnewman) Date: 2010-01-23 02:14
Telnet.interact() is failing on Python 3.1.1 Windows, but works fine on Python 2.6.4 Windows and also works on Python 3.1.1 Linux. See 3 examples below:

--- Test #1 (fails): Telnet.interact on Python 3.1.1 Windows --- 

Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from telnetlib import Telnet
>>> tn = Telnet("scn.org", 23)
>>> tn.interact()
Unhandled exception in thread started by <bound method Telnet.listener of <telnetlib.Telnet object at 0x00C3C3F0>>
Traceback (most recent call last):
  File "C:\python31\lib\telnetlib.py", line 566, in listener
    sys.stdout.write(data)
TypeError: must be str, not bytes
# (I press enter again):
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\python31\lib\telnetlib.py", line 528, in interact
    self.mt_interact()
  File "C:\python31\lib\telnetlib.py", line 555, in mt_interact
    self.write(line)
  File "C:\python31\lib\telnetlib.py", line 277, in write
    if IAC in buffer:
TypeError: 'in <string>' requires string as left operand, not bytes

--- Test #2 (works): Telnet.interact on Python 2.6.4 Windows ---

Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from telnetlib import Telnet
>>> tn = Telnet("scn.org", 23)
>>> tn.interact()

Seattle Community Network Sun Solaris 1.1.1.B
Please login as 'visitor' if you are a visitor


SunOS UNIX (scn)

login:

--- Test #3 (works): Telnet.interact on Python 3.1.1 Linux ---

mike@ebx2009:~$ python3.1
Python 3.1.1 (r311:74480, Oct 18 2009, 19:21:53) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from telnetlib import Telnet
>>> tn = Telnet("scn.org", 23)
>>> tn.interact()

Seattle Community Network Sun Solaris 1.1.1.B
Please login as 'visitor' if you are a visitor


SunOS UNIX (scn)

login:
msg110000 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-11 12:19
This works fine with Python 2.7 on Windows.
msg110017 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-07-11 14:39
Confirmed with 3.1. Raising priority, since it seems to be one of those
bytes/string issues that prevent people from using py3k.
msg110098 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2010-07-12 15:40
Can you check this on 3.1.2 or 3.2?  There were a few bugfixes of the bytes handling in that timeframe.
msg110100 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-12 15:48
I get the same error on Windows for 3.1.2 as the OP did for 3.1.1.
msg110103 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-07-12 16:05
3.2 is affected as well.
msg119428 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-23 14:16
The attached patch should fix the problem.  It replicates the bytes/string changes made for the unix branch in the windows branch.

It would be nice to come up with a unit test for this, but in this case that's a lot more complicated than figuring out the fix :)
msg119448 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2010-10-23 16:51
The patch works. I agree that no test is needed, since no one will
attempt to revert this. :)
msg119538 - (view) Author: Jack Diederich (jackdied) * (Python committer) Date: 2010-10-25 03:27
Thanks David, do you want to apply?  Looks good to me.
msg119606 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-26 12:47
Committed to py3k in r85846, 3.1 in r85847.
History
Date User Action Args
2022-04-11 14:56:56adminsetgithub: 52009
2010-10-26 12:47:59r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg119606

stage: test needed -> resolved
2010-10-25 03:27:50jackdiedsetmessages: + msg119538
2010-10-23 16:51:18skrahsetmessages: + msg119448
2010-10-23 14:16:40r.david.murraysetfiles: + telnetlib_windows.patch

nosy: + r.david.murray
messages: + msg119428

keywords: + patch
2010-07-12 16:05:40skrahsetmessages: + msg110103
2010-07-12 15:48:28BreamoreBoysetmessages: + msg110100
2010-07-12 15:40:35jackdiedsetpriority: high -> normal

nosy: + jackdied
messages: + msg110098

assignee: jackdied
2010-07-11 14:43:12ezio.melottisetnosy: + ezio.melotti

stage: needs patch -> test needed
2010-07-11 14:40:42skrahsetstage: test needed -> needs patch
2010-07-11 14:40:00skrahsetpriority: normal -> high
nosy: + skrah
messages: + msg110017

2010-07-11 12:19:27BreamoreBoysetnosy: + BreamoreBoy

messages: + msg110000
versions: + Python 3.2
2010-01-23 15:26:20brian.curtinsetpriority: normal
nosy: + brian.curtin

type: behavior
stage: test needed
2010-01-23 02:14:58mnewmancreate