all Python 3until 3.13Removed from the standard libraryterm
telnetlib
removed modules
Client for the Telnet protocol. Removed in Python 3.13 — use asyncio streams or the telnetlib3 and Exscript packages; use SSH for remote login.
Syntax
import telnetlib # до 3.13
telnetlib.Telnet(host, port) opened a connection, write() sent bytes, read_until(b'login: ') waited for a prompt — this is how network devices and training servers were scripted. PEP 594 dropped it: Telnet sends passwords in clear text, and the module was barely maintained. How to port: reader, writer = await asyncio.open_connection(host, port) gives the same connection, writer.write() plus await writer.drain() sends, await reader.readuntil(b'login: ') waits for the prompt. asyncio does not negotiate Telnet options (IAC); telnetlib3 and Exscript do, and the standard-telnetlib package restores the old module. For remote login use SSH, for example paramiko or asyncssh.
Examples
# Python 3.13+
try:
import telnetlib
except ModuleNotFoundError as e:
print(type(e).__name__) # → ModuleNotFoundError
# Python 3.13+
import asyncio
async def serve(reader, writer):
writer.write(b'login: ')
await writer.drain()
writer.close()
async def main():
server = await asyncio.start_server(serve, '127.0.0.1', 0)
port = server.sockets[0].getsockname()[1]
reader, writer = await asyncio.open_connection('127.0.0.1', port)
print(await reader.readuntil(b'login: ')) # → b'login: '
writer.close()
server.close()
asyncio.run(main())
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy