python-websockets / websockets

Library for building WebSocket servers and clients in Python

Home Page:https://websockets.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

0 bytes read on a total of 2 expected bytes

dontbanmeplz opened this issue · comments

commented

on localhost my program is working fine, but as soon as i try to host it on a server I get this error like 30s to 1m after my client connects
no idea why this could be happening

= connection is CONNECTING

GET / HTTP/1.1
Host: decrypt-ws.starfiles.co
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: vPKjA6sDUmZ7TAFMSmKC0Q==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
User-Agent: Python/3.7 websockets/11.0.3
< HTTP/1.1 101 Switching Protocols
< Date: Sun, 25 Feb 2024 03:28:25 GMT
< Connection: upgrade
< Upgrade: websocket
< Sec-WebSocket-Accept: W+jzdsgVl2jQRyG8if6r3bbWc7Y=
< CF-Ray: 85acdbb01cbc1141-ORD
< CF-Cache-Status: BYPASS
< Vary: Accept-Encoding
< Cf-Placement: local-ORD
< I2p-Location: http://decrypt-ws.vnt23fy3n5qiwojrkcec2i3ac6w5gkacdyrf2gobid6xjnq53ffq.b32.i2p/
< Onion-Location: http://decrypt-ws.starfilesmj35tuw5bf7qaxfpf4d6tydvqjbftzw23t3ghtjreyx45id.onion/
< Report-To: {"endpoints":[{"url":"https://a.nel.cloudflare.com/report/v3?s=T4dGQBKXUAL2TY31EgqJ9rsb6JjiCdK3sG5RqgeZOT5YO3odzi7kKNfGt84DrNG4OWOqxgTpSk6vrzX5BxLvMWWXhwNfD2E4JS3WJxUZIxIvOnMMq%2FQllQzbE0ff8XuVZHB5%2FlURrJe5"}],"group":"cf-nel","max_age":604800}
< NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
< expect-ct: max-age=86400, enforce
< referrer-policy: same-origin
< x-content-type-options: nosniff
< x-frame-options: SAMEORIGIN
< x-xss-protection: 1; mode=block
< Server: cloudflare
< alt-svc: h3=":443"; ma=86400
= connection is OPEN
started
% sending keepalive ping
PING 19 8c 1b 0c [binary, 4 bytes]
< PING b2 c3 fe e2 [binary, 4 bytes]
PONG b2 c3 fe e2 [binary, 4 bytes]
< PONG 19 8c 1b 0c [binary, 4 bytes]
% received keepalive pong
% sending keepalive ping
PING 'ԩ\x0fQ' [text, 4 bytes]
< PING 22 5d 93 ce [binary, 4 bytes]
PONG 22 5d 93 ce [binary, 4 bytes]
< PONG 'ԩ\x0fQ' [text, 4 bytes]
% received keepalive pong
= connection is CLOSED
! failing connection with code 1006
x closing TCP connection

Traceback (most recent call last):
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 959, in transfer_data
message = await self.read_message()
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 1029, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 1104, in read_data_frame
frame = await self.read_frame(max_size)
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 1165, in read_frame
extensions=self.extensions,
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/framing.py", line 68, in read
data = await reader(2)
File "/usr/lib/python3.7/asyncio/streams.py", line 677, in readexactly
raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "main.py", line 74, in
asyncio.run(handle_connection(uri))
File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
return future.result()
File "main.py", line 58, in handle_connection
message = await websocket.recv()
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 568, in recv
await self.ensure_open()
File "/var/mobile/.local/lib/python3.7/site-packages/websockets/legacy/protocol.py", line 935, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

commented

@aaugustin I understand why it's happening.
What can i do to resolve this problem?