flyte / upnpclient

uPnP client library for Python 3.
MIT License
204 stars 37 forks source link

Error 404 Client Error #39

Open l0rddarkf0rce opened 2 years ago

l0rddarkf0rce commented 2 years ago

I have the following simple code

import upnpclient
def findWiiM():
    WiiMServer = None
    devices = upnpclient.discover()
    for dev in devices:
        if dev.friendly_name == 'WiiM Mini':
            WiiMServer = dev.location
    return WiiMServer

print(findWiiM())

and when I run it I get the following error?

Error '404 Client Error: Not Found for url: http[:]//192.168.1.220:8060/dial/ecp_SCPD.xml' for <upnpclient.ssdp.Entry object at 0x000001F68CB1E310>

Any ideas on how to ignore and/or fix it?

l0rddarkf0rce commented 2 years ago

The error occurs by just running upnpclient.discover()

sanderjo commented 2 years ago

Same error here.

$ python3 
Python 3.8.10 (default, Jun 22 2022, 20:18:18) 
[GCC 9.4.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.178.39:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f2ed160>
Error '404 Client Error: Not Found for url: http://192.168.178.37:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4c40>
Error '404 Client Error: Not Found for url: http://192.168.178.37:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4d60>
Error '404 Client Error: Not Found for url: http://192.168.178.39:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f0991a45d90>
Error '404 Client Error: Not Found for url: http://192.168.178.39:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4dc0>
Error '404 Client Error: Not Found for url: http://192.168.178.37:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4df0>
Error '404 Client Error: Not Found for url: http://192.168.178.39:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4ee0>
Error '404 Client Error: Not Found for url: http://192.168.178.37:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4f40>
Error '404 Client Error: Not Found for url: http://192.168.178.39:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4fa0>
Error '404 Client Error: Not Found for url: http://192.168.178.37:8008/ssdp/notfound' for <upnpclient.ssdp.Entry object at 0x7f098f1b4fd0>
>>> 
sanderjo commented 2 years ago

Ugly workaround: temporarily redirect stderror to /dev/null:

safe_stderr = sys.stderr
sys.stderr = open(os.devnull,'w')
devices = upnpclient.discover()
sys.stderr = safe_stderr
sanderjo commented 2 years ago

I assume the error is from:

https://github.com/flyte/upnpclient/blob/develop/upnpclient/ssdp.py#L126

I'm not sure, but maybe you can overwrite that ... ?

        log = _getLogger("ssdp")
        log.error("Error '%s' for %s", exc, entry)

EDIT: Commenting out that line in .local/lib/python3.8/site-packages/upnpclient/ssdp.py indeed avoids the error message

sanderjo commented 1 year ago

Any feedback on this?

Anything better than the workaround below?

#!/usr/bin/env python3

import upnpclient
import sys, os

# workaround: redirect stderr
safe_stderr = sys.stderr
sys.stderr = open(os.devnull,'w')
devices = upnpclient.discover()
sys.stderr = safe_stderr

for i in devices:
    print(i)
    try:
        print(i.WANIPConn1.GetExternalIPAddress())
    except:
        pass