Platform Onvif: urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

Hello,

I’m trying to setup my onvif camera without any success - Who has a hint for me how to solve this error:

Traceback (most recent call last):
File “/etc/homeassistant/deps/onvif/client.py”, line 34, in wrapped
return func(*args, **kwargs)
File “/etc/homeassistant/deps/onvif/client.py”, line 201, in wrapped
return call(params, callback)
File “/etc/homeassistant/deps/onvif/client.py”, line 191, in call
ret = func(**params)
File “/etc/homeassistant/deps/suds/client.py”, line 559, in call
return client.invoke(args, kwargs)
File “/etc/homeassistant/deps/suds/client.py”, line 618, in invoke
result = self.send(soapenv)
File “/etc/homeassistant/deps/suds/client.py”, line 652, in send
reply = transport.send(request)
File “/etc/homeassistant/deps/suds/transport/http.py”, line 178, in send
return HttpTransport.send(self, request)
File “/etc/homeassistant/deps/suds/transport/http.py”, line 78, in send
fp = self.u2open(u2request)
File “/etc/homeassistant/deps/suds/transport/http.py”, line 119, in u2open
return url.open(u2request, timeout=tm)
File “/usr/lib/python3.4/urllib/request.py”, line 455, in open
response = self._open(req, data)
File “/usr/lib/python3.4/urllib/request.py”, line 473, in _open
‘_open’, req)
File “/usr/lib/python3.4/urllib/request.py”, line 433, in _call_chain
result = func(*args)
File “/usr/lib/python3.4/urllib/request.py”, line 1202, in http_open
return self.do_open(http.client.HTTPConnection, req)
File “/usr/lib/python3.4/urllib/request.py”, line 1176, in do_open
raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

I tested it with a FLOUREON SP012 and a Sricam SP017 - Basically with the Onvif App it is working, so the Onvif feature is working on the cam:

Thanks, Tom

I guess you’re not in a virtual env of python. You could try the fix component I’ve made, while the fix gets merged. See link below
(ONVIF camera)

I applied the fix, but the error still persist:

2017-07-25 11:46:42 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform onvif
Traceback (most recent call last):
  File "/usr/lib/python3.4/urllib/request.py", line 1174, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/usr/lib/python3.4/http/client.py", line 836, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 491, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/etc/homeassistant/deps/onvif/client.py", line 34, in wrapped
    return func(*args, **kwargs)
  File "/etc/homeassistant/deps/onvif/client.py", line 201, in wrapped
    return call(params, callback)
  File "/etc/homeassistant/deps/onvif/client.py", line 191, in call
    ret = func(**params)
  File "/etc/homeassistant/deps/suds/client.py", line 559, in __call__
    return client.invoke(args, kwargs)
  File "/etc/homeassistant/deps/suds/client.py", line 618, in invoke
    result = self.send(soapenv)
  File "/etc/homeassistant/deps/suds/client.py", line 652, in send
    reply = transport.send(request)
  File "/etc/homeassistant/deps/suds/transport/http.py", line 178, in send
    return HttpTransport.send(self, request)
  File "/etc/homeassistant/deps/suds/transport/http.py", line 78, in send
    fp = self.u2open(u2request)
  File "/etc/homeassistant/deps/suds/transport/http.py", line 119, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/lib/python3.4/urllib/request.py", line 455, in open
    response = self._open(req, data)
  File "/usr/lib/python3.4/urllib/request.py", line 473, in _open
    '_open', req)
  File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 1202, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.4/urllib/request.py", line 1176, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 164, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
    res = func(*args, **kw)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/camera/onvif.py", line 48, in async_setup_platform
    async_add_devices([ONVIFCamera(hass, config)])
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/camera/onvif.py", line 70, in __init__
    self._input = media.GetStreamUri().Uri
  File "/etc/homeassistant/deps/onvif/client.py", line 36, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: <urlopen error [Errno -2] Name or service not known>

Content of onvif.py:

"""
Support for ONVIF Cameras with FFmpeg as decoder.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/camera.onvif/
"""
import asyncio
import logging

import voluptuous as vol

from homeassistant.const import (
    CONF_NAME, CONF_HOST, CONF_USERNAME, CONF_PASSWORD, CONF_PORT)
from homeassistant.components.camera import Camera, PLATFORM_SCHEMA
from homeassistant.components.ffmpeg import (
    DATA_FFMPEG)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.aiohttp_client import (
    async_aiohttp_proxy_stream)

_LOGGER = logging.getLogger(__name__)

REQUIREMENTS = ['onvif-py3==0.1.3',
                'suds-py3==1.3.3.0',
                'http://github.com/tgaugry/suds-passworddigest-py3'
                '/archive/86fc50e39b4d2b8997481967d6a7fe1c57118999.zip'
                '#suds-passworddigest-py3==0.1.2a']
DEPENDENCIES = ['ffmpeg']
DEFAULT_NAME = 'ONVIF Camera'
DEFAULT_PORT = 5000
DEFAULT_USERNAME = 'admin'
DEFAULT_PASSWORD = '888888'

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
    vol.Required(CONF_HOST): cv.string,
    vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
    vol.Optional(CONF_PASSWORD, default=DEFAULT_PASSWORD): cv.string,
    vol.Optional(CONF_USERNAME, default=DEFAULT_USERNAME): cv.string,
    vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
})


@asyncio.coroutine
def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
    """Set up a ONVIF camera."""
    if not hass.data[DATA_FFMPEG].async_run_test(config.get(CONF_HOST)):
        return
    async_add_devices([ONVIFCamera(hass, config)])


class ONVIFCamera(Camera):
    """An implementation of an ONVIF camera."""

    def __init__(self, hass, config):
        """Initialize a ONVIF camera."""
        from onvif import ONVIFService
        import onvif
        import os
        super().__init__()

        self._name = config.get(CONF_NAME)
        self._ffmpeg_arguments = '-q:v 2'
        media = ONVIFService(
            'http://{}:{}/onvif/device_service'.format(
                config.get(CONF_HOST), config.get(CONF_PORT)),
            config.get(CONF_USERNAME),
            config.get(CONF_PASSWORD),
            '{}/wsdl/media.wsdl'.format(os.path.dirname(onvif.__file__))
        )
        self._input = media.GetStreamUri().Uri
        _LOGGER.debug("ONVIF Camera Using the following URL for %s: %s",
                      self._name, self._input)

    @asyncio.coroutine
    def async_camera_image(self):
        """Return a still image response from the camera."""
        from haffmpeg import ImageFrame, IMAGE_JPEG
        ffmpeg = ImageFrame(
            self.hass.data[DATA_FFMPEG].binary, loop=self.hass.loop)

        image = yield from ffmpeg.get_image(
            self._input, output_format=IMAGE_JPEG,
            extra_cmd=self._ffmpeg_arguments)
        return image

    @asyncio.coroutine
    def handle_async_mjpeg_stream(self, request):
        """Generate an HTTP MJPEG stream from the camera."""
        from haffmpeg import CameraMjpeg

        stream = CameraMjpeg(self.hass.data[DATA_FFMPEG].binary,
                             loop=self.hass.loop)
        yield from stream.open_camera(
            self._input, extra_cmd=self._ffmpeg_arguments)

        yield from async_aiohttp_proxy_stream(
            self.hass, request, stream,
            'multipart/x-mixed-replace;boundary=ffserver')
        yield from stream.close()

    @property
    def name(self):
        """Return the name of this camera."""
        return self._name

What do you have in the config?

This is my config:

camera:
  - platform: onvif
    host: _MYLOCALADDRESS_
    name: Cam
    username: _USERNAME_
    password: _PASSWORD_
    port: 5000

You don’t need to specify the port as it defaults to 5000.
For the sricams try without specifying the username and password and use the cameras ip.

camera:
  - platform: onvif
    host: ipaddress
    name: Cam

Also try the updated custom_component 20170724

Try adding the debug logging as shown in this post onvif debug

Updated the component and removed the port from the config. I cannot remove username/password because I changed them. Still the same error.

I’d still give it a go without the username and password as my sricams has the credentials changed but the cam doesn’t seem to use, it only uses them when changing settings via the android app.

Did you add the debug logging? If you did can you post the log output?

I propose just to wait a few days until your fix is applied to the next HASS version. Just to be sure I’m applied the change wrongly :slight_smile:

Updated to 0.50 and got the same error. Doesn’t matter if I pass the credentials and port or not :frowning: - Any ideas how to troubleshoot?

I’m trying to set this up as well. I have an Escam QD300. When I open http://192.168.178.105:5000 in a browser I get an XML. No password needed. In my config is just the IP as it defaults to port 5000.

My logging:

2017-08-21 21:05:01 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform onvif
Traceback (most recent call last):
  File "/srv/hass/lib/python3.5/site-packages/onvif/client.py", line 34, in wrapped
    return func(*args, **kwargs)
  File "/srv/hass/lib/python3.5/site-packages/onvif/client.py", line 201, in wrapped
    return call(params, callback)
  File "/srv/hass/lib/python3.5/site-packages/onvif/client.py", line 191, in call
    ret = func(**params)
  File "/srv/hass/lib/python3.5/site-packages/suds/client.py", line 559, in __call__
    return client.invoke(args, kwargs)
  File "/srv/hass/lib/python3.5/site-packages/suds/client.py", line 618, in invoke
    result = self.send(soapenv)
  File "/srv/hass/lib/python3.5/site-packages/suds/client.py", line 652, in send
    reply = transport.send(request)
  File "/srv/hass/lib/python3.5/site-packages/suds/transport/http.py", line 178, in send
    return HttpTransport.send(self, request)
  File "/srv/hass/lib/python3.5/site-packages/suds/transport/http.py", line 78, in send
    fp = self.u2open(u2request)
  File "/srv/hass/lib/python3.5/site-packages/suds/transport/http.py", line 119, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1257, in do_open
    r = h.getresponse()
  File "/usr/lib/python3.5/http/client.py", line 1197, in getresponse
    response.begin()
  File "/usr/lib/python3.5/http/client.py", line 297, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python3.5/http/client.py", line 266, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 164, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 392, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 206, in coro
    res = func(*args, **kw)
  File "/home/hass/.homeassistant/custom_components/camera/onvif.py", line 48, in async_setup_platform
    async_add_devices([ONVIFCamera(hass, config)])
  File "/home/hass/.homeassistant/custom_components/camera/onvif.py", line 70, in __init__
    self._input = media.GetStreamUri().Uri
  File "/srv/hass/lib/python3.5/site-packages/onvif/client.py", line 36, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Remote end closed connection without response

What xml are you getting from the camera when you connect via a browser?
I’m thinking the ONVIF library has a problem in it so i’m trying to add in some error handling and possibly swapping the library for a better one.
I’m currently waiting for a couple of other ONVIF cameras to arrive.

@matt2005

Here you are my XML:


-<SOAP-ENV:Fault xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:tdn="http://www.onvif.org/ver10/network/wsdl" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsdd="http://schemas.xmlsoap.org/ws/2005/04/discovery" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope">

<faultcode>SOAP-ENV:Client</faultcode>

<faultstring>HTTP GET method not implemented</faultstring>

</SOAP-ENV:Fault>

Can you try port 8899? I’ve read a few sites that mention escam qd300 and onvif port 8899.

Port 5000 is the only tcp port, which is open on that device. 8899 is closed.

What camera is it?

Currently it’s a https://www.amazon.de/gp/product/B071W823Q7/ref=oh_aui_detailpage_o09_s00?ie=UTF8&psc=1 - I had the same behaviour with that one: https://www.amazon.de/gp/product/B01N9NWRTD/ref=oh_aui_detailpage_o09_s00?ie=UTF8&psc=1

Hmm, that’s similar to my cameras.
Are you using it’s IP in the config?
Here is what i use for one of my cameras.

- platform: onvif
  host: 192.168.1.192
  name: Cam1

That is exactly what I have in my config:

  - platform: onvif
    host: 192.168.1.178.215
    name: Cam

Logs:

2017-08-25 00:15:51 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform onvif
Traceback (most recent call last):
  File "/usr/lib/python3.4/urllib/request.py", line 1174, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.4/http/client.py", line 1090, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.4/http/client.py", line 1128, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.4/http/client.py", line 1086, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.4/http/client.py", line 924, in _send_output
    self.send(msg)
  File "/usr/lib/python3.4/http/client.py", line 859, in send
    self.connect()
  File "/usr/lib/python3.4/http/client.py", line 836, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python3.4/socket.py", line 491, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.4/socket.py", line 530, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/onvif/client.py", line 34, in wrapped
    return func(*args, **kwargs)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/onvif/client.py", line 201, in wrapped
    return call(params, callback)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/onvif/client.py", line 191, in call
    ret = func(**params)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/suds/client.py", line 559, in __call__
    return client.invoke(args, kwargs)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/suds/client.py", line 618, in invoke
    result = self.send(soapenv)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/suds/client.py", line 652, in send
    reply = transport.send(request)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/suds/transport/http.py", line 178, in send
    return HttpTransport.send(self, request)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/suds/transport/http.py", line 78, in send
    fp = self.u2open(u2request)
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/suds/transport/http.py", line 119, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/lib/python3.4/urllib/request.py", line 455, in open
    response = self._open(req, data)
  File "/usr/lib/python3.4/urllib/request.py", line 473, in _open
    '_open', req)
  File "/usr/lib/python3.4/urllib/request.py", line 433, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.4/urllib/request.py", line 1202, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.4/urllib/request.py", line 1176, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity_component.py", line 164, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
    res = func(*args, **kw)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/camera/onvif.py", line 49, in async_setup_platform
    async_add_devices([ONVIFCamera(hass, config)])
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/camera/onvif.py", line 70, in __init__
    self._input = media.GetStreamUri().Uri
  File "/etc/homeassistant/deps/lib/python3.4/site-packages/onvif/client.py", line 36, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: <urlopen error [Errno -2] Name or service not known>

I’m running HA 0.51.2

Sorry! It was just a horrible dumb typo :exploding_head: - Look at the IP address in my config :crazy_face: