core: Can't authorise Withings

Home Assistant release with the issue:

0.99.0

Last working Home Assistant release (if known):

Operating environment (Hass.io/Docker/Windows/etc.):

Hass.io Component/platform:

https://www.home-assistant.io/components/withings/

Description of problem:

Can’t authorise the app, get error:

500 Internal Server Error Server got itself in trouble

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):


Traceback (if applicable):


Additional information:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 8
  • Comments: 64 (11 by maintainers)

Most upvoted comments

the maintainer confirmed the Project is dead. I’ll fork and fix this weekend

Tldr: upstream dependency needs an update, waiting for that change.

Based on my local tests, it appears withings requires a client id even though it was working before the HA release. The dependent Nokia api already accommodates this but never issued a new release. I submitted a ticket to publish the fix to pip. Then we can update component. https://github.com/orcasgit/python-nokia/issues/38

Same here for docker.

Fix is ready to be merged. BTW: Here’s the new maintained withings api project. https://github.com/vangorra/python_withings_api

Hass.io-users can utilize the following work-around to fix this:

Install the “Custom deps deployment”-addon from the addon-store. Add the following to the config and run it:

{
  "pypi": [
    "nokia"
  ],
  "apk": []
}

You should then in your config-folder find /deps/lib/python3.7/site-packages/nokia. Open __init__.py in your favorite text editor and scroll to line 82.

Change

    def get_credentials(self, code):
        tokens = self._oauth().fetch_token(
            '%s/oauth2/token' % self.URL,
            code=code,
            client_secret=self.consumer_secret)

to

    def get_credentials(self, code):
        tokens = self._oauth().fetch_token(
            '%s/oauth2/token' % self.URL,
            code=code,
            client_secret=self.consumer_secret,
            include_client_id=True)

Save the file and restart Home Assistant. Configure the integration again and it will finish.

edit: you should delete the nokia-folder when this evenutually is fixed in the library.

I had the same problem ( Server got itself in trouble/Missing token). I’m running HA on a raspberry in docker ( homeassistant/home-assistant:0.99.0 ).

To be able to successfully finish the config flow, I had to change a line in the nokia lib ( https://github.com/orcasgit/python-nokia/blob/1.2.0/nokia/__init__.py#L86 ). In my docker container it’s in /usr/local/lib/python3.7/site-packages/nokia/__init__.py

I’ve added , include_client_id=True

to the fetch_token() call.

We are waiting on the Nokia python library being updated, which is out off the hands of the HomeAssistant people.

This is the only supported method of connecting. Withings requires the URL you provide must be https running in port 443 and is accessible. Their servers check when you set the callback URL for the developer account.

For development purposes, your can work around this very easily if you understand how oauth2 works. This method is unsupported, hence it does not exist in the documentation as it gets complicated. When setting up you withings dev account, the callback URL can be anything that withings can check is online when you setup your developer account, like https://myblackhole.somedomain.com/auth/external/callback. So long as that has a valid certificate and responds at all, the withings server is satisfied. You can even shut off the http server after setting up the dev account. Withings doesn’t recheck, as far as I can tell. On the HA side, your base URL needs to be https://myblackhole.somedomain.com. When you setup then integration, the withings server will require you to authorize this app and redirect you to https://myblackhole.somedomain.com/auth/external/callback with a lot of data on the path. Just replace https://myblackhole.somedomain.com in the URL with the internal address of the HA instance that started the setup. Something like http://10.10.0 22:8123

Glad it’s working for people, great component! Credit for the fix should absolutely go to @derfloh (https://github.com/home-assistant/home-assistant/issues/26716#issuecomment-533351754), I just put the pieces together for Hass.io 😃

As mentioned and referenced above, this is an issue with the python-nokia library, not Home Assistant. It will need to be resolved there in order that the changes propagate through to HA.

Yeah, and what exactly needs to be done and by whom to resolve this issue? What’s expected resolution time?

@chriswood1001 Try setting your “internal url” to your duckdns one. That’s how I got it to work on my setup

With HA Version 0.100.1 and 0.100.2 after i click on “allow this app” i got the error “call to the webservice failed” . Has anyone else the same problem by activate the witings connection to Home Assistant? (API URI URL and HA URL are reachable from the web)

Yes, I also get the message “call to the webservice failed” with HA Version 0.100.2. With version before 0.100 I got the message “500 Internal Server Error”.

If we did any of the workarounds here do we need to change something back once it’s in the release?

Try to look at https://github.com/orcasgit/python-nokia/issues/38 And ask for a solution

I’m afraid it is a bit too complicated for me. But when you have identified the problem and on top of that found a solution, we can hope that there will be a fix very soon. Could you perhaps post the revised file, so that it is just a question of copying it to the right place?

My understanding of this issue is due to a change in withings API and a request as been made for the lib: https://github.com/orcasgit/python-nokia/issues/38