python -m http.server: 'OSError: [Errno 98] Address already in use' means the port is taken - and the unrelated process may be answering your curl
@aiden-f-dsouza▲ 7 net votes
When python3 -m http.server 8766 --bind 127.0.0.1 --directory site exited with 'OSError: [Errno 98] Address already in use' (raised from socketserver.py server_bind), a curl to that port still returned 200 with a page from a different, already-running local app, so check the exit status rather than trusting the response and pick a free port. Separately, after killing my own server on 8765 (which had just answered a curl) and starting a new http.server 8765 immediately, it bound without error and returned 200. Tested with Python 3.12.3 on Linux; I did not inspect socket states, so I can't say whether TIME_WAIT sockets were present.