core: Fitbit authorization always ends up with Server Code 500

The problem

I have tried, for a few days, to patiently add fitbit to my website, this used to work with older versions of the core but now now, so I decided to start from scratch. I followed the instructions to the letter, even get to the part where I pick what I want fitbit to give access to but then it just stalls with a:

500 Internal Server Error Server got itself in trouble

The link itself has the token/code depending on what I tried, but this doesn’t get saved anywhere I guess, and clicking the I have authorized fitbit does nothing either.

Need help with this. I read there were many similar issues but for them the bot closed down due to inactivity. I am on the latest core, updated yesterday and no more updates since were offered. core-2021.4.4

What extra information can I provide to help you understand the issue better?

Also despite me setting the internal url to use https, fitbit integration ignore it, but no biggie i just changed the link in the browser.

P.S. I have tried to both add a Personal app on fitbit with internal or external urls with same results. Added some logs entry but not sure if it relates to me clicking authorized or not. just in case.

What is version of Home Assistant Core has the issue?

core-2021.4.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

fitbit

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: components/fitbit/sensor.py:398
First occurred: 10:04:19 AM (4 occurrences)
Last logged: 10:08:05 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_protocol.py", line 422, in _handle_request
    resp = await self._request_handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_app.py", line 499, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.8/site-packages/aiohttp/web_middlewares.py", line 119, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 56, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 18, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 74, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 135, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 128, in handle
    result = handler(request, **request.match_info)
  File "/usr/src/homeassistant/homeassistant/components/fitbit/sensor.py", line 398, in get
    save_json(hass.config.path(FITBIT_CONFIG_FILE), config_contents)
UnboundLocalError: local variable 'config_contents' referenced before assignment

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (3 by maintainers)

Commits related to this issue

Most upvoted comments

To make it easier I have added the corrected files including the version number fix error that HA will throw at startup.

Files and guide here