Reputation: 1
I'm running this code in VS Code:
import asyncio
async def tcp_echo_client(message):
reader, writer = await asyncio.open_connection(
'127.0.0.1', 80)
print(f'Send: {message!r}')
writer.write(message.encode())
await writer.drain()
data = await reader.read(100)
print(f'Received: {data.decode()!r}')
print('Close the connection')
writer.close()
await writer.wait_closed()
asyncio.run(tcp_echo_client('Hello World!'))
It's exactly the same in Python's original docs, but I have no idea why I get that error.
In Spyder the error's a little different:
RuntimeError: asyncio.run() cannot be called from a running event loop
I also tried different IPs and ports.
When I tried another IP like Google's DNS, (8.8.8.8), I encountered this another weird error:
OSError: [WinError 121] The semaphore timeout period has expired
Upvotes: 0
Views: 1814