[Python] TCP Messages starting with REST verb are not send

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am making a very strange observation while using python sockets to send TCP data:

    When sending a TCP packet over a new connection that starts with "PUT ", "POST ", "DELETE " or "GET ", the messages are only send much later when the socket is closed.

    Some details:

    • Sending anything else (at least all the messages i could think of) works fine (is send immediately)
    • Sending "PUT " etc. as a second message (and something else first) works fine.
    • Sending something else after the "PUT " message is also not send.
    • The space is necessary, i.e. "POST" works fine. The data after the space does not change anything, i.e. "POST some more data" is also not send immediately.
    • The socket.sendall call immediately returns, but the TCP packet is not send until the socket is closed. This is confirmed with a Wireshark log.
    • I tried the TCP_NODELAY sockopt without success.

    import socket
    from time import sleep

    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect(("198.18.2.2", 8764))

    sock.sendall(b"PUT ")
    sleep(10)


    this leads to the "PUT " only being send 10s later. See Wireshark log:

    No Time Source Destination Len Info
    1 0.000000 198.18.2.1 198.18.2.2 TCP 66 59465 → 8764 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 WS=256 SACK_PERM
    2 0.000813 198.18.2.2 198.18.2.1 TCP 60 8764 → 59465 [SYN, ACK] Seq=0 Ack=1 Win=512 Len=0 MSS=1460
    3 0.000976 198.18.2.1 198.18.2.2 TCP 54 59465 → 8764 [ACK] Seq=1 Ack=1 Win=64240 Len=0
    4 10.003259 198.18.2.1 198.18.2.2 TCP 58 "PUT " (0x50 0x55 0x54 0x20)
    5 10.003331 198.18.2.1 198.18.2.2 TCP 54 59465 → 8764 [FIN, ACK] Seq=5 Ack=1 Win=64240 Len=0
    6 10.004227 198.18.2.2 198.18.2.1 TCP 60 8764 → 59465 [ACK] Seq=1 Ack=5 Win=508 Len=0
    7 10.011112 198.18.2.2 198.18.2.1 TCP 60 8764 → 59465 [FIN, ACK] Seq=1 Ack=6 Win=508 Len=0
    8 10.011318 198.18.2.1 198.18.2.2 TCP 54 59465 → 8764 [ACK] Seq=6 Ack=2 Win=64240 Len=0


    I am out of ideas where to check for the root cause of this. Apparently some REST verbs are treated differently. By Python? Windows? TCP?

    Continue reading...

Compartilhe esta Página