2

I would appreciate it if someone could take a look at this issue:

I am using a Reolink IP camera to regularly query a still image via Python. The camera is connected to a TP Link switch via a LAN cable. The switch is connected to a Belkin Ethernet to USB-C adapter via a LAN cable. The adapter is connected to my Macbook Air M2 via USB-C.

I receive a camera image via the Reolink client software and I can also adjust the camera settings.

The IP address of the Ethernet interface (Belkin Adapter) is set to 192.168.0.204. The IP address of the camera is set to 192.168.0.201.

I can successfully access the camera's IP address via “ping”

Both the HTTP (80) and RTSP (554) ports are open and accessible.

I can query the RTSP stream via ffmpeg and VLC Media Player successfully.

However, when I make an HTTP request via Python, I get the error “Failed to establish a new connection: [Errno 65] No route to host.”

I have almost the same setup on my Windows PC, but I connect the switch directly to the PC's internal Ethernet interface via a LAN cable. The exact same Python script works without any problems here.

Does anyone have any idea what the problem could be? This is my example python code:

import requests

url = "http://192.168.0.201/snapshot.jpg"
auth = ("username", "password")

response = requests.get(url, auth=auth)

if response.status_code == 200:
    with open("snapshot.jpg", "wb") as f:
        f.write(response.content)
    print("Snapshot saved!")
else:
    print("Error:", response.status_code)
1
  • Check if ports 80 or 443 are listening. If 443 is there then it's https Commented Nov 1 at 15:14

2 Answers 2

1

I was able to fix the problem myself... I always started my Python script via the Visual Studio Code terminal. On macOS, VS Code apparently did not have permission to search for devices on the local network. Therefore, the request was blocked. The setting can be found under “System Settings” => “Privacy & Security” => “Local Network.” The switch must be flipped for VS Code.

Sign up to request clarification or add additional context in comments.

Comments

0

The EHOSTUNREACH "no route to host" can come about in two different ways.

  1. no matching route shown by netstat -rn, due to wrong mask, missing default route, etc.
  2. an ICMP Unreachable came back, either from a router or from the host

You say that your Mac can ping -c3 192.168.0.201 successfully, so that's good. It rules out that first possibility. Apparently everyone is using a /24 mask, and arp -n 192.168.0.201 properly reports the ether address of the camera.

Verify with telnet 192.168.0.201 http that it's listening on port 80, rather than giving an immediate "connection refused".

Having got this far, I'd worry about the webserver issuing a 301 redirect to a port or host that is unreachable, perhaps 443 for https. Use curl -v to verify. Notice that you can ask the requests library to not chase redirects, if you want.

Final debugging step would be to resort to tcpdump / wireshark. Start with just sudo tcpdump -s 1500 icmp to see if any host unreach or port unreach ICMPs come back. Then capture all traffic to the camera, to see its three-way handshake and other TCP details.

10 Comments

Hello, thanks for taking the time to answer my question!
For context: "en9" is my ethernet adapter. Here you can find the result of netstat command: limewire.com/d/aW7YE#FEXxpqU0qy
When i ping -c3 192.168.0.201 it says: 3 packets transmitted, 3 packets received, 0.0% packet loss. LOOKS OK!
arp command result: "? (192.168.0.201) at ec:71:db:31:ed:a3 on en9 ifscope [ethernet]"
telnet result: Trying 192.168.0.201... Connected to 192.168.0.201. Looks also ok!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.