Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tesla integration goes unavailable (with traceback) #49354

Closed
bdraco opened this issue Apr 17, 2021 · 58 comments · Fixed by #49939
Closed

Tesla integration goes unavailable (with traceback) #49354

bdraco opened this issue Apr 17, 2021 · 58 comments · Fixed by #49939

Comments

@bdraco
Copy link
Member

bdraco commented Apr 17, 2021

The problem

Unexpected error fetching tesla data: tuple index out of range

What is version of Home Assistant Core has the issue?

dev

What was the last working version of Home Assistant Core?

dev

What type of installation are you running?

Home Assistant Core

Integration causing the issue

tesla

Link to integration documentation on our website

https://www.home-assistant.io/integrations/tesla/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-04-17 19:15:21 ERROR (MainThread) [homeassistant.components.tesla] Unexpected error fetching tesla data: tuple index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 179, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/components/tesla/__init__.py", line 262, in _async_update_data
    return await self.controller.update()
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 661, in update
    cars = await self.get_vehicles()
  File "/usr/local/lib/python3.8/site-packages/backoff/_async.py", line 133, in retry
    ret = await target(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 357, in get_vehicles
    return (await self.__connection.get("vehicles"))["response"]
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 78, in get
    return await self.post(command, "get", None)
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 96, in post
    self.code = await self.get_authorization_code(
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 372, in get_authorization_code
    code_url = URL(resp.history[-1].url)
IndexError: tuple index out of range

Additional information

No response

@probot-home-assistant
Copy link

tesla documentation
tesla source
(message by IssueLinks)

@bdraco
Copy link
Member Author

bdraco commented Apr 17, 2021

2021-04-17 19:40:21 DEBUG (MainThread) [teslajsonpy.connection] Oauth expiration detected
2021-04-17 19:40:21 DEBUG (MainThread) [teslajsonpy.connection] Getting sso auth code using credentials
2021-04-17 19:40:21 DEBUG (MainThread) [teslajsonpy.connection] Getting sso auth token from https://auth.tesla.com/oauth2/v3/authorize?client_id=ownerapi&code_challenge=<snip>%3D%3D&code_challenge_method=S256&redirect_uri=https://auth.tesla.com/void/callback&response_type=code&scope=openid+email+offline_access&state=<snip>-miNLGIgHkANFae3C9xiiKTc9YILBqqsMQhsg
2021-04-17 19:40:21 DEBUG (MainThread) [teslajsonpy.connection] POST: 
https://auth.tesla.com/oauth2/v3/authorize?client_id=ownerapi&code_challenge=<snip>%3D%3D&code_challenge_method=S256&redirect_uri=https://auth.tesla.com/void/callback&response_type=code&scope=openid+email+offline_access&state=<snip>-miNLGIgHkANFae3C9xiiKTc9YILBqqsMQhsg with
<CIMultiDictProxy('Host': 'auth.tesla.com', 'User-Agent': 'HomeAssistant/2021.5.0.dev0 aiohttp/3.7.4.post0 Python/3.8', 'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate', 'Content-Length': '51', 'Content-Type': 'application/x-www-form-urlencoded')>
 returned 403:Forbidden with response <CIMultiDictProxy('Server': 'AkamaiGHost', 'Mime-Version': '1.0', 'Content-Type': 'text/html', 'Content-Length': '294', 'Expires': 'Sat, 17 Apr 2021 19:40:21 GMT', 'Date': 'Sat, 17 Apr 2021 19:40:21 GMT', 'Connection': 'close')>

@bdraco
Copy link
Member Author

bdraco commented Apr 17, 2021

Manually reloading the config entry did result in recovery

@monsieurlatte
Copy link

Reload didnt work for me. I get
`Log Details (ERROR)
Logger: homeassistant.components.tesla
Source: components/tesla/init.py:273
Integration: Tesla (documentation, issues)
First occurred: 3:10:59 PM (1 occurrences)
Last logged: 3:10:59 PM

Unexpected error fetching tesla data: tuple index out of range
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 173, in _async_refresh
self.data = await self._async_update_data()
File "/usr/src/homeassistant/homeassistant/components/tesla/init.py", line 273, in _async_update_data
return await self.controller.update()
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 661, in update
cars = await self.get_vehicles()
File "/usr/local/lib/python3.8/site-packages/backoff/_async.py", line 133, in retry
ret = await target(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 357, in get_vehicles
return (await self.__connection.get("vehicles"))["response"]
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 78, in get
return await self.post(command, "get", None)
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 96, in post
self.code = await self.get_authorization_code(
File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 372, in get_authorization_code
code_url = URL(resp.history[-1].url)
IndexError: tuple index out of range
`

@mvaneijken
Copy link

Same here, reinstall the integration result in being unable to sign-in withe error mentioned above and the error message on the login screen: "Unknown error occurred". Not using MFA.

@monsieurlatte
Copy link

Same here, reinstall the integration result in being unable to sign-in withe error mentioned above and the error message on the login screen: "Unknown error occurred". Not using MFA.

Yeah same here, also not using MFA.

@rhdny
Copy link

rhdny commented Apr 18, 2021

Same. Occurred following upgrade from 2021.4.4 to 2021.4.5. Reloaded, restarted HA and host. Not using MFA.

@monsieurlatte
Copy link

Mine was fine after upgrading to 2021.4.5 for a while, it just started today for some reason.

@rhdny
Copy link

rhdny commented Apr 18, 2021

Maybe it was the sign-in after the restart that got me.

@rhdny
Copy link

rhdny commented Apr 18, 2021

I temporarily flipped back to the Homebridge Tesla plugin and re-enabled it. It's working fine, so it seems the issue is not on the Tesla side.

@akballow
Copy link

Same getting the ```IndexError: tuple index out of range
Error. Reload fixes it temporary, sometimes. I think tis Tesla side issue with api

@mattsch
Copy link
Contributor

mattsch commented Apr 18, 2021

Having the same issue with and without MFA enabled. Reported upstream at zabuldon/teslajsonpy#190.

@offlinehoster
Copy link

Reload and reconfig as a new integration is not working

2021-04-18 21:29:10 ERROR (MainThread) [aiohttp.server] 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 131, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 155, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 60, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 107, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 156, in async_configure
    result = await self._async_handle_step(flow, cur_step["step_id"], user_input)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 214, in _async_handle_step
    result: dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/tesla/config_flow.py", line 57, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/usr/src/homeassistant/homeassistant/components/tesla/config_flow.py", line 159, in validate_input
    (config[CONF_TOKEN], config[CONF_ACCESS_TOKEN]) = await controller.connect(
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 268, in connect
    cars = await self.get_vehicles()
  File "/usr/local/lib/python3.8/site-packages/backoff/_async.py", line 133, in retry
    ret = await target(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/controller.py", line 357, in get_vehicles
    return (await self.__connection.get("vehicles"))["response"]
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 78, in get
    return await self.post(command, "get", None)
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 96, in post
    self.code = await self.get_authorization_code(
  File "/usr/local/lib/python3.8/site-packages/teslajsonpy/connection.py", line 372, in get_authorization_code
    code_url = URL(resp.history[-1].url)
IndexError: tuple index out of range

@rwarner
Copy link

rwarner commented Apr 19, 2021

Also have 2021.4.4 and am getting this tuple issue after restarting HA. After the initial Integration setup on my instance.

@DibblesNL
Copy link

Same same

@mischoe
Copy link

mischoe commented Apr 19, 2021

Everything worked until 2 days ago... 2021.4.5 didn´t change anything back to good. MFA is disabled
Anybody working on this ?

@dompol171
Copy link

Same ;) - stopped working with 2021.4.4 and doesn't work with 2021.4.5

@Schelin78
Copy link

Same here

@pvmil
Copy link

pvmil commented Apr 19, 2021

Same issue here with 2014.4.4 and .5, I see the issue is fixed and waits for merge teslajsonpy, hope this gets merged into a HA bugfix release

@jesusmarcos
Copy link

Same error here. Let's hope the solution is merged soon.

@rwarner
Copy link

rwarner commented Apr 20, 2021

Looks like the suggested PR has been denied / closed: #46558

??

@IIDemoniaKII
Copy link

Hello, same problem here !

@skrenes
Copy link

skrenes commented Apr 20, 2021

All was working fine last Friday until I installed 2021.4.5. When HA rebooted, the Tesla integration had the tuple index out of range error. It's still broken with 2021.4.6.

@alandtse
Copy link
Contributor

Tesla is likely blocking the login attempt now on some unknown factor (e.g. user agent). I suggested a new architecture for logins in the closed PR as I believe that mechanism will be easier to maintain but that was denied.

I will be continuing the new architecture as a custom component but will not be working on the login here. I will continue to review any PRs in the official integration so if you can code python you may have to step up.

@Schelin78
Copy link

Not working with both latest updates

@folrewef
Copy link

I also use Teslamate. I have no issue there.

@wencevdm
Copy link

Same here, stopped working even before updating to 2021.4.6. Which is logical since as alandtse said it's Tesla blocking the login attempt.

@Schelin78
Copy link

Rollback to core-2021.3.4 works.

Sorry stoped working after a while

@freshfieldx
Copy link

Just an observation, but if I reload the integration, around 50% of the time my Tesla data updates once, then fails again.

@rudyo85
Copy link

rudyo85 commented Apr 26, 2021

Stopped working here too, following this thread for a solution

@freshfieldx
Copy link

freshfieldx commented Apr 26, 2021

RIP aiohttp

Lets hope httpx helps us here.

https://github.com/zabuldon/teslajsonpy/issues/190

@alandtse
Copy link
Contributor

Custom component is out. I may have to change the name since it conflicts with core.

Use HACS to install. If you're replacing core, you will need to remove your existing core integration and add the custom component. This will force a new login using the new method.

If you're using my Alexa Media Player component, make sure you've signed in recently to AMP as the login will be broken in AMP until the next release.

@tobbensoft
Copy link

tobbensoft commented Apr 29, 2021

Works fine, very nice. 👍

Did need to "authenticate" 2 times, for it to login.

@monsieurlatte
Copy link

works here too, well done!!

@jherby2k
Copy link

jherby2k commented Apr 29, 2021

Works great! i didn't have to authenticate twice like @tobbensoft did. Smooth transition.

So is the "official" Tesla integration DOA then? Or can these httpx / aiohttp changes be made separate from the rejected PR?

@alandtse
Copy link
Contributor

So is the "official" Tesla integration DOA then? Or can these httpx / aiohttp changes be made separate from the rejected PR?

I don't intend to fix the login issues with config flow but the teslajsonpy library has the necessary functions so someone else could fix the login. Assuming it gets fixed, then I'll continue to review other commits that add functionality. Assuming they get merged, I'll also port them to the custom component.

@zephyrus9MA
Copy link

zephyrus9MA commented Apr 29, 2021

Custom component is out. I may have to change the name since it conflicts with core.

Use HACS to install. If you're replacing core, you will need to remove your existing core integration and add the custom component. This will force a new login using the new method.

If you're using my Alexa Media Player component, make sure you've signed in recently to AMP as the login will be broken in AMP until the next release.

Little help please! Used HACS to install. Log file:

2021-04-29 15:01:40 WARNING (MainThread) [homeassistant.loader] You are using a custom integration tesla_cc which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-04-29 15:01:40 WARNING (MainThread) [homeassistant.loader] No 'version' key in the manifest file for custom integration 'tesla_cc'. As of Home Assistant 2021.6, this integration will no longer be loaded. Please report this to the maintainer of 'tesla_cc'
2021-04-29 15:01:40 WARNING (MainThread) [homeassistant.loader] You are using a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-04-29 15:01:44 ERROR (MainThread) [homeassistant.setup] Error during setup of component tesla_cc
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 242, in _async_setup_component
    result = await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/tesla_cc/__init__.py", line 42, in setup
    from tesla_api import TeslaApiClient, AuthenticationError, ApiError
ModuleNotFoundError: No module named 'tesla_api'

My configuration.yaml (snippet):
tesla_cc: !include tesla.yaml

@yurgh
Copy link

yurgh commented Apr 30, 2021

Little help please! Used HACS to install. Log file:

That's the wrong component.

From memory:
In HACS go to Integration, then open the more-menu to the far right. Select Custom Repository. Enter the URL https://github.com/alandtse/tesla in the top input field, select integration as category and press add.

Remove the "Homeassistant Teslacustomcomponent" component, and restart Home Assistant.

In HACS search for and add the Tesla custom integration. Restart HA.

In HA go to configuration, intgrations and click add integration. Search for Tesla and add "Tesla Custom Integration". Log in on the page that follows

@zephyrus9MA
Copy link

zephyrus9MA commented Apr 30, 2021

That's the wrong component.

From memory:
In HACS go to Integration, then open the more-menu to the far right. Select Custom Repository. Enter the URL https://github.com/alandtse/tesla in the top input field, select integration as category and press add.

Remove the "Homeassistant Teslacustomcomponent" component, and restart Home Assistant.

In HACS search for and add the Tesla custom integration. Restart HA.

In HA go to configuration, intgrations and click add integration. Search for Tesla and add "Tesla Custom Integration". Log in on the page that follows

Worked! Thanks.

@Schelin78
Copy link

Hi, gets the values with custom but gets this error in logs:

Logger: homeassistant.helpers.integration_platform
Source: loader.py:490
First occurred: 10:29:08 (4 occurrences)
Last logged: 10:29:08

Unexpected error importing tesla_custom/group.py
Unexpected error importing tesla_custom/system_health.py
Unexpected error importing tesla_custom/logbook.py
Unexpected error importing tesla_custom/media_source.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 30, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 485, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 490, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.tesla.group'

@alandtse
Copy link
Contributor

alandtse commented Apr 30, 2021

Unexpected error importing tesla_custom/group.py
Unexpected error importing tesla_custom/system_health.py
Unexpected error importing tesla_custom/logbook.py
Unexpected error importing tesla_custom/media_source.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 30, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 485, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 490, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.tesla.group'

  1. Remove the integration,
  2. Remove from HACS
  3. Confirm custom_components/tesla is gone
  4. Reinstall in HACS

@pvmil
Copy link

pvmil commented Apr 30, 2021

Really nice thanks, the plugin works. Would still be nice to have this in ha core though...
But thanks a lot for your effort

@Schelin78
Copy link

Unexpected error importing tesla_custom/group.py
Unexpected error importing tesla_custom/system_health.py
Unexpected error importing tesla_custom/logbook.py
Unexpected error importing tesla_custom/media_source.py
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/integration_platform.py", line 30, in _process
platform = integration.get_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 485, in get_platform
cache[full_name] = self._import_platform(platform_name)
File "/usr/src/homeassistant/homeassistant/loader.py", line 490, in _import_platform
return importlib.import_module(f"{self.pkg_path}.{platform_name}")
File "/usr/local/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1014, in _gcd_import
File "", line 991, in _find_and_load
File "", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'custom_components.tesla.group'

  1. Remove the integration,
  2. Remove from HACS
  3. Confirm custom_components/tesla is gone
  4. Reinstall in HACS

Thanks works fine now

@GeoffCampbell
Copy link

Custom component is out. I may have to change the name since it conflicts with core.

Just to confirm, this is working fine for me. Thanks for all your work sorting it out.

alandtse added a commit to alandtse/home-assistant that referenced this issue May 1, 2021
Teslajsonpy has switched from aiohttp to httpx which should
resolve random connection issues. MFA will not work in this version.

closes home-assistant#49354
closes home-assistant#46937
closes home-assistant#46156
closes home-assistant#30443
@alandtse
Copy link
Contributor

alandtse commented May 1, 2021

I just realized that I might be able to fix logins for anyone without MFA by updating the dependency. I am unable to test it as I use MFA, but it may work. If someone confirms it works for non-MFA, we can merge it in. Please check #49939

The custom component includes this fix plus MFA support and other quality improvements.

EDIT: @bdraco has confirmed it has some additional work to get it to work.

bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
bdraco added a commit to bdraco/home-assistant that referenced this issue May 1, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jun 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.