ClementNerma / tapo-rest

An unofficial REST API to remotely control Tapo devices
44 stars 3 forks source link

Python - HostUnreachable on Azure Functions #14

Closed mjensen-gh closed 3 weeks ago

mjensen-gh commented 3 weeks ago

When running this locally I have no issue, also works fine using Azure Core Tools. When deploying this to an Azure Function App I am getting this error. I am able to get the ApiClient fine, the moment I try to initialize any device I get the error below.

File "/home/site/wwwroot/function_app.py", line 44, in http_trigger await setup_devices() File "/home/site/wwwroot/function_app.py", line 23, in setup_devices device = await client.generic_device("192.168.0.167") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Exception: Http(reqwest::Error { kind: Request, url: "http://192.168.0.167/app", source: hyper_util::client::legacy::Error(Connect, ConnectError("tcp connect error", Os { code: 113, kind: HostUnreachable, message: "No route to host" })) })

ClementNerma commented 3 weeks ago

That means the IP you've specified in the URL (192.168.0.167) is unreachable. The IP you're using refers to your local network, so if you deploy it on Azure it can't be reached. You need to make it available, for instance by setting up a VPN relay. There are tons of different ways to do this, each with their own security implications. But usually, I would advise against controlling your local devices from an online platform, as it can be a source of security problems.

mjensen-gh commented 3 weeks ago

Thanks for the clarification. I did know that 192.168.0.167 is a local IP address. My initial assumption was that the the Tapo module would authenticate to Tapo cloud the same way the mobile app does, and that local IP address was just a reference to the device not that it actually authenticates to that IP address. Thanks anyways as I've been running it on a local server for a while and it works great.

ClementNerma commented 3 weeks ago

The authentication is performed on the device, which in turns I believe authenticates against the cloud. But you need a local access in order to reach the API exposed by the device (the one that tapo-rest uses).