home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.74k stars 29.99k forks source link

Freebox component unable to connect at Freebox ! #20734

Closed vincegre closed 5 years ago

vincegre commented 5 years ago

Home Assistant release with the issue: 0.86.4 Last working Home Assistant release (if known): first time use of that component Operating environment (Hass.io/Docker/Windows/etc.): Hassio supervisor 142, HassOS 2.8 Component/platform: https://www.home-assistant.io/components/freebox/

Description of problem: add-on is unable to connect at Freebox, generates lot of errors in HA logs:

Error during setup of component freebox

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "uvloop/loop.pyx", line 1879, in create_connection
  File "uvloop/loop.pyx", line 1857, in uvloop.loop.Loop.create_connection
  File "uvloop/handles/tcp.pyx", line 178, in uvloop.loop.TCPTransport.connect
  File "uvloop/handles/tcp.pyx", line 200, in uvloop.loop._TCPConnectRequest.connect
OSError: [Errno 101] Network unreachable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
    hass, processed_config)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/freebox.py", line 50, in async_setup
    await async_setup_freebox(hass, config, host, port)
  File "/usr/local/lib/python3.6/site-packages/homeassistant/components/freebox.py", line 76, in async_setup_freebox
    await fbx.open(host, port)
  File "/usr/local/lib/python3.6/site-packages/aiofreepybox/aiofreepybox.py", line 64, in open
    self._access = await self._get_freebox_access(host, port, self.api_version, self.token_file, self.app_desc, self.timeout)
  File "/usr/local/lib/python3.6/site-packages/aiofreepybox/aiofreepybox.py", line 102, in _get_freebox_access
    app_token, track_id = await self._get_app_token(base_url, app_desc, timeout)
  File "/usr/local/lib/python3.6/site-packages/aiofreepybox/aiofreepybox.py", line 159, in _get_app_token
    r = await self.session.post(url, data=data, timeout=timeout)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.6/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.6/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host eixlytoz.fbxos.fr:761 ssl:None [Network unreachable]

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant): As documented for add-on I accessed the special URL that allows to retrieve control port and dns name of my freebox and copy/pasted these in conf.yaml:

freebox:
  host: eixlytoz.fbxos.fr
  port: 761

Additional information:

If you need additional tests, please let me know ;)

vincegre commented 5 years ago

No news on this ? One more non working component in ha :(

SNoof85 commented 5 years ago

Hi ! I worked on this component :) Sorry for the delay, i missed your issue :/ Could you please give me the output of : http://mafreebox.freebox.fr/api_version ? Also could you check if you have a file freebox.conf in your config folder and give here the content of this file ?

Thx

vincegre commented 5 years ago

Could you please give me the output of : http://mafreebox.freebox.fr/api_version ?

Sure here it is:

box_model_name | "Freebox Server Mini (r2)"
api_base_url | "/api/"
https_port | 761
device_name | "freebox"
https_available | true
box_model | "fbxgw-r2/mini"
api_domain | "eixlytoz.fbxos.fr"
uid | "f41bc7549c88454b0b0ea4e5bebdbacc"
api_version | "6.0"
device_type | "FreeboxServer1,2"

Mini Freebox 4K (no TV player only ADSL/Fiber box)

Also could you check if you have a file freebox.conf in your config folder and give here the content of this file ?

No that file doesn't exist ! Am I supposed to create it ? as I have seen nothing about that or is it created automatically by the component ?

Side note: I use also the Free app to manage/see state of the freebox server and one time on two when I open it I get that error (second try is always good !): screenshot_20190222-085149

SNoof85 commented 5 years ago

If the freebox.conf file is not generated (the component creates this file, don't create it by your own) 2 possibilities :

In the freebox web admin : could you check in "Paramètres de la Freebox" > "Gestion des accès" > "Applications". Normaly you should see at least your freebox compagnon app. Is there here any failed associations ?

What you can also try : the component is able to discover the freebox if discovery is enabled on your Home Assistant configuration. So you can try to comment out the freebox platform configuration.

vincegre commented 5 years ago

The component never hits freebox: I guess it's the case as I never got the authorisation request on screen of Freebox and it doesn't appear in failed attempt too in Applications section of Freebox ! Only the companion app appears there !! discovery is always active in my config of HA but I commented out Freebox section and restarted HA, it doesn't detect the freebox by itself !! I tried also a telnet on the alias eixly... that resolves at my public IPv4 and 6 on port 761 but I get a Connection refused ! and same using mafreebox.freebox.fr !

SNoof85 commented 5 years ago

OK :) Are you with xDSL or fiber ? If you are with xDSL, do you have a full stack ip ? You can check this out in your Free account.

vincegre commented 5 years ago

OK :) Are you with xDSL or fiber ? If you are with xDSL, do you have a full stack ip ? You can check this out in your Free account.

I'm with fiber and I have a full stack IP since ever (had to do it for plex server ;) !

SNoof85 commented 5 years ago

You have no DMZ setup on the freebox ? It's acting as router ? (just looking for any difference with my own) Can you try to set the 443 https port for remote access ? I know that you changed it for some reason but just a try !

vincegre commented 5 years ago

You have no DMZ setup on the freebox ? It's acting as router ? (just looking for any difference with my own)

No DMZ, it's setup as router, nothing fancy here, DHCP setup on LAN, and just two ports routed !

Can you try to set the 443 https port for remote access ? I know that you changed it for some reason but just a try !

Same with 443 :( What do you mean ? I didn't change anything there, it was by default on 761 ! If I try to access the API endpoint it's well updated with port 443 but same as before, impossible connection :(

Even on 443 HA discovery doesn't detect freebox !! and manual setup is not more efficient !

Should I activate the option: Remote access with password ? unless I guess it's only for the access at web interface of Freebox and not for API !

SNoof85 commented 5 years ago

=====> Oh, yes, you have to enable this ! That's written in the component doc. Did not know that free set some fancy ports for https by default ;)

Edit : well this option needs to be active but it's not clearly stated in the doc. The docs says to set a password. Not to activate this option. But you have to activate it. Which is as you told, a bit stupid regarding the option name...

vincegre commented 5 years ago

=====> Oh, yes, you have to enable this ! That's written in the component doc. Edit : well this option needs to be active but it's not clearly stated in the doc. The docs says to set a password. Not to activate this option. But you have to activate it. Which is as you told, a bit stupid regarding the option name...

oki so I activated the option but not better :( I have tried both in 443 et 761 but same ! I still can't connect to these ports from terminal and in HA it triggers that:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "uvloop/loop.pyx", line 1879, in create_connection
  File "uvloop/loop.pyx", line 1857, in uvloop.loop.Loop.create_connection
  File "uvloop/handles/tcp.pyx", line 178, in uvloop.loop.TCPTransport.connect
  File "uvloop/handles/tcp.pyx", line 200, in uvloop.loop._TCPConnectRequest.connect
OSError: [Errno 101] Network unreachable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/setup.py", line 151, in _async_setup_component
    hass, processed_config)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/freebox/__init__.py", line 45, in async_setup
    await async_setup_freebox(hass, config, host, port)
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/freebox/__init__.py", line 71, in async_setup_freebox
    await fbx.open(host, port)
  File "/usr/local/lib/python3.7/site-packages/aiofreepybox/aiofreepybox.py", line 64, in open
    self._access = await self._get_freebox_access(host, port, self.api_version, self.token_file, self.app_desc, self.timeout)
  File "/usr/local/lib/python3.7/site-packages/aiofreepybox/aiofreepybox.py", line 102, in _get_freebox_access
    app_token, track_id = await self._get_app_token(base_url, app_desc, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiofreepybox/aiofreepybox.py", line 159, in _get_app_token
    r = await self.session.post(url, data=data, timeout=timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 992, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 931, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host eixlytoz.fbxos.fr:443 ssl:None [Network unreachable]

Did not know that free set some fancy ports for https by default ;)

I think it's due to the IPV6 native mode by default now on new Free Lines (whatever you are in xDSL or Fiber you don't get anymore a fully routed IP and so they have to do some not so nice stuffs with ports ! As full stack IP is always activated after, it keeps probably the creepy port setup at first run ;)

SNoof85 commented 5 years ago

OK, i was looking at some points and you probably right about IPv6. You have IPv6 activated in your free account ? Mine not... We could also try with aiofreepybox some trick. I do not have the time yet, but i'll try to give you some steps to modify some simple code into aiofreepybox to try something :)

vincegre commented 5 years ago

OK, i was looking at some points and you probably right about IPv6. You have IPv6 activated in your free account ? Mine not...

Nope deactivated it as soon as I got full IPV4 stack (so long there is no firewall for IPV6 in freebox it's not an option to activate it !!). Side note: connection is still full IPV6 (IPV4 is done through a tunneling in Free network !).

We could also try with aiofreepybox some trick. I do not have the time yet, but i'll try to give you some steps to modify some simple code into aiofreepybox to try something :)

oki no problem, let me know when you can what I shoud try ;) Thanks

SNoof85 commented 5 years ago

Could you try to modify aiofreepybox.py line 62 from :

conn = aiohttp.TCPConnector(ssl_context=ssl_ctx)

to : conn = aiohttp.TCPConnector(ssl_context=ssl_ctx, family=socket.AF_INET)

vincegre commented 5 years ago

Could you try to modify aiofreepybox.py line 62 from :

conn = aiohttp.TCPConnector(ssl_context=ssl_ctx)

to : conn = aiohttp.TCPConnector(ssl_context=ssl_ctx, family=socket.AF_INET)

Will check how to do that as I'm using hassio and will let you know result ;)

SNoof85 commented 5 years ago

Found a colleague, new user of hassio with Mini 4k too and full stack IPv4 asked to Free after being in shared IPv4. He has same behaviour. He left me access to his hassio instance, i'll check what i can do also on my side ;)

vincegre commented 5 years ago

Found a colleague, new user of hassio with Mini 4k too and full stack IPv4 asked to Free after being in shared IPv4. He has same behaviour. He left me access to his hassio instance, i'll check what i can do also on my side ;)

Oh cool so I'm not alone ;) For info 4.0.4 Freebox server version ! The most strange is that the freebox doesn't have port open whatever I setup 443 or put back the original 761 :(

SNoof85 commented 5 years ago

Hm, unfortunately the box Permettre nouvelles demandes d'associations was not ticked on his box... and now it's working :/ So you're back alone with this issue ! What makes me think it's a Fbx issue, is the fact you have also problems with official compagnon app.

Let me invoke aiofreepybox guru @stilllman :) Maybe he'll have an idea !

SNoof85 commented 5 years ago

If you have any linux at home can you try nmap -p 761 eixlytoz.fbxos.fr when your https_port is 761 (by default) just checking it's opened.

SNoof85 commented 5 years ago

Oh ! another tought : in Paramètres de la Freebox > Gestion des ports > connexions entrantes > Accès à distance sécurisé à Freebox OS is set to true for both "Autorisé" and "Actif" and the port is the same than configured in Paramètres de la Freebox > Configuration > Port accès distant sécurisé ?

vincegre commented 5 years ago

What makes me think it's a Fbx issue, is the fact you have also problems with official compagnon app.

Hard-reboot of Freebox ??

If you have any linux at home can you try nmap -p 761 eixlytoz.fbxos.fr when your https_port is 761 (by default) just checking it's opened.

nmap indicates port filtered as I told you previously ;)

Oh ! another tought : in Paramètres de la Freebox > Gestion des ports > connexions entrantes > Accès à distance sécurisé à Freebox OS is set to true for both "Autorisé" and "Actif" and the port is the same than configured in Paramètres de la Freebox > Configuration > Port accès distant sécurisé ?

Very good point and I didn't imagine Freebox OS to be so poorly designed and not open automatically ports needed or at least asking for :( And why does it need to open the port while connection is from LAN ??? Now it's working fine and I guess you can tweak adjust documentation of component so others don't do the same mistake :+1:

Thanks for all and sorry for issue ;)

SNoof85 commented 5 years ago

Glad you can now use this ;) I will think about some doc more explicit on this.

AntMCE commented 4 years ago

I am having a similar issue. The Freebox won't display "autoriser l'application"

Freebox mini 4K OS 4.0.7

Terminal logs do not show any attempt of connection nor error message

Thanks in advance for your time PS: my IT knowledge is very limited

denics commented 3 years ago

Dear all, sorry to add to this but I really do not understand. I have a kodi installation with the pvr.freebox plugin installed and it works like charm using the address mafreebox.free.fr . However, I cannot get this plugin even to reach the freebox. I have a freebox mini 4K in bridge mode, followed by an openwrt that manage my network. Services are dispatched using haproxy (nextcloud, home assistant, etc).

This is what my api sais:

box_model_name | "Freebox Server Mini (r2)"
api_base_url | "/api/"
https_port | 8443
device_name | "freebox"
https_available | true
box_model | "fbxgw-r2/mini"
api_domain | "mydomain.fbxos.fr"
uid | ""
api_version | "8.1"
device_type | "FreeboxServer1,2"

This is the last configuration I tried. With this configuration, I get:

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host mydomain.fbxos.fr:8443 ssl:default [Network unreachable]

Am I missing something in openwrt? firewall? forwarding? why is the kodi plugin working correctly? I can help you debug in case so we can improve the docs. Thanks.

simonc56 commented 1 year ago

Raspberry Pi 2 HAOS 9.4 HomeAssistant 2022.12.5 Freebox 6 (Revolution)

Impossible to pair the freebox device : Unexpected error when i start pairing.

Logger: homeassistant.components.freebox.config_flow
Source: components/freebox/config_flow.py:75
Integration: Freebox (documentation, issues)
First occurred: 15:39:14 (5 occurrences)
Last logged: 15:51:00

Unknown error connecting with Freebox router at 4slldzyv.fbxos.fr
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 986, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)  # type: ignore[return-value]  # noqa
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1064, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 1049, in create_connection
    sock = await self._connect_sock(
  File "/usr/local/lib/python3.10/asyncio/base_events.py", line 960, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 500, in sock_connect
    return await fut
  File "/usr/local/lib/python3.10/asyncio/selector_events.py", line 535, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
ConnectionRefusedError: [Errno 111] Connect call failed ('82.66.190.103', 22916)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/freebox/config_flow.py", line 75, in async_step_link
    await fbx.open(self._host, self._port)
  File "/usr/local/lib/python3.10/site-packages/freebox_api/aiofreepybox.py", line 83, in open
    self._access = await self._get_freebox_access(
  File "/usr/local/lib/python3.10/site-packages/freebox_api/aiofreepybox.py", line 162, in _get_freebox_access
    app_token, track_id = await self._get_app_token(base_url, app_desc, timeout)
  File "/usr/local/lib/python3.10/site-packages/freebox_api/aiofreepybox.py", line 226, in _get_app_token
    r = await self._session.post(url, data=data, timeout=timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 535, in _request
    conn = await self._connector.connect(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 542, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 907, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1206, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 1175, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host 4slldzyv.fbxos.fr:22916 ssl:default [Connect call failed ('82.66.190.103', 22916)]