upnpclient
upnpclient copied to clipboard
upnpclient.discover() gives on STDERR: "Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x78b888017050>"
I get the errors below
sander@zwarte:~$ ./venv-upnpclient/bin/python3
Python 3.12.3 (main, Nov 6 2024, 18:32:19) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import upnpclient
>>> devices = upnpclient.discover()
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x78b888017050>
Error ''NoneType' object has no attribute 'strip'' for <upnpclient.ssdp.Entry object at 0x78b8880ad8b0>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x78b8880591f0>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x78b888016a50>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x78b888059bb0>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x78b888059730>
but devices is nicely filled:
>>> devices
[<Device 'veilingbrug (192.168.1.218)'>, <Device 'Sagemcom Fast5598'>]
That output is to STDERR:
sander@zwarte:~/venv-upnpclient$ bin/python3 testje.py 1>stdout.txt 2>stderr.txt
sander@zwarte:~/venv-upnpclient$
sander@zwarte:~/venv-upnpclient$ cat stderr.txt
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x73272bffe060>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x73272bffe090>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x73272bffe0c0>
Error ''NoneType' object has no attribute 'strip'' for <upnpclient.ssdp.Entry object at 0x73272ba77260>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x73272bffdcd0>
Error '404 Client Error: Not Found for url: http://192.168.1.15:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x73272a905f10>
That 192.168.1.15 seems to a Google device, possibly my Google Chromecast:
sander@zwarte:~/git/upnpclient$ sudo nmap -O 192.168.1.15
Starting Nmap 7.95 ( https://nmap.org ) at 2025-01-01 20:05 CET
Nmap scan report for Huiskamer-chromecast (192.168.1.15)
Host is up (0.011s latency).
Not shown: 995 closed tcp ports (reset)
PORT STATE SERVICE
8008/tcp open http
8009/tcp open ajp13
8443/tcp open https-alt
9000/tcp open cslistener
10001/tcp open scp-config
MAC Address: 1C:53:F9:03:6B:6B (Google)
Device type: media device
Running: Google Android
OS CPE: cpe:/o:google:android
OS details: Google Chromecast with Google TV (Android)
Network Distance: 1 hop
OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 4.63 seconds
Workaround: temporarily send STDERR to /dev/null
import os
import sys
import upnpclient
f = open(os.devnull, 'w')
print("go")
oldstderr = sys.stderr
sys.stderr = f
devices = upnpclient.discover()
print(devices)
sys.stderr = oldstderr
print("done")
... and ... clean console output:
sander@zwarte:~/venv-upnpclient$ bin/python3 scan_test.py
go
[<Device 'Sagemcom Fast5598'>, <Device 'veilingbrug (192.168.1.218)'>]
done
It uses the logging library to show these errors, and can be easily suppressed like this:
import logging
logging.getLogger("ssdp").setLevel(logging.CRITICAL)