Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python -m http.server fails with OSError: Socket is not connected #129166

Open
smallmoonzz opened this issue Jan 22, 2025 · 1 comment
Open

python -m http.server fails with OSError: Socket is not connected #129166

smallmoonzz opened this issue Jan 22, 2025 · 1 comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@smallmoonzz
Copy link

smallmoonzz commented Jan 22, 2025

# Bug report

### Bug description:

(base) ➜  ~ python -m http.server 8000
Serving HTTP on :: port 8080 (http://[::]:8080/) ...
----------------------------------------
Exception occurred during processing of request from None
Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.12/socketserver.py", line 692, in process_request_thread
    self.finish_request(request, client_address)
  File "/opt/anaconda3/lib/python3.12/http/server.py", line 1311, in finish_request
    self.RequestHandlerClass(request, client_address, self,
  File "/opt/anaconda3/lib/python3.12/http/server.py", line 672, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/anaconda3/lib/python3.12/socketserver.py", line 761, in __init__
    self.handle()
  File "/opt/anaconda3/lib/python3.12/http/server.py", line 436, in handle
    self.handle_one_request()
  File "/opt/anaconda3/lib/python3.12/http/server.py", line 404, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/lib/python3.12/socket.py", line 720, in readinto
    return self._sock.recv_into(b)
           ^^^^^^^^^^^^^^^^^^^^^^^
OSError: [Errno 57] Socket is not connected
----------------------------------------

os: Darwin moonzzMacBook-Pro.local 24.2.0 Darwin Kernel Version 24.2.0: Fri Dec 6 18:41:43 PST 2024; root:xnu-11215.61.5~2/RELEASE_X86_64 x86_64
my ip : 192.168.148.212
my vmware ubuntn ip : 192.168.73.182

I user python -m http.server run http server in my mac, run tomcat on port 8080

in mac: use curl 192.168.148.212:8000,got the error, curl localhost:8000 got ok
in ubuntn use curl 192.168.148.212:8000,got the error。

i use wireshark catch it 1.pcap, you can get it from cat 1.txt | base64 -d > 1.pcap

Image

1.txt

(base) ➜  Downloads sudo tcpdump 'tcp port 8000 || tcp port 8080'
tcpdump: data link type PKTAP
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on pktap, link-type PKTAP (Apple DLT_PKTAP), snapshot length 524288 bytes
12:12:05.925789 IP 192.168.73.182.60256 > 192.168.148.212.irdmi: Flags [S], seq 1949593479, win 64240, options [mss 1460,sackOK,TS val 423466448 ecr 0,nop,wscale 7], length 0
12:12:05.926113 IP 192.168.148.212.irdmi > 192.168.73.182.60256: Flags [S.], seq 1076460035, ack 1949593480, win 64240, options [mss 1460], length 0
12:12:05.926317 IP 192.168.73.182.60256 > 192.168.148.212.irdmi: Flags [.], ack 1, win 64240, length 0
12:12:05.926470 IP 192.168.73.182.60256 > 192.168.148.212.irdmi: Flags [P.], seq 1:85, ack 1, win 64240, length 84
12:12:05.926574 IP 192.168.148.212.irdmi > 192.168.73.182.60256: Flags [.], ack 85, win 64240, length 0
12:12:05.933618 IP 192.168.148.212.irdmi > 192.168.73.182.60256: Flags [FP.], seq 1, ack 85, win 64240, length 0
12:12:05.934082 IP 192.168.73.182.60256 > 192.168.148.212.irdmi: Flags [F.], seq 85, ack 2, win 64239, length 0
12:12:05.934208 IP 192.168.148.212.irdmi > 192.168.73.182.60256: Flags [.], ack 86, win 64239, length 0

other versions of my python also hit this, did it is related to python or macos?

CPython versions tested on:

3.12

Operating systems tested on:

macOS

@smallmoonzz smallmoonzz added the type-bug An unexpected behavior, bug, or error label Jan 22, 2025
@smallmoonzz
Copy link
Author

sorry,my mistake.

It is the tcp fin packet send by the firewall,the problem disapper after close the firewall.

# see state of firewall
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate

# list allow apps
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --listapps

@encukou encukou added the stdlib Python modules in the Lib dir label Jan 22, 2025
@encukou encukou changed the title python -m http.server python -m http.server fails with OSError: Socket is not connected Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants