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

Unable to add Tesla integration #46397

Closed
oscfor opened this issue Feb 11, 2021 · 45 comments
Closed

Unable to add Tesla integration #46397

oscfor opened this issue Feb 11, 2021 · 45 comments

Comments

@oscfor
Copy link

oscfor commented Feb 11, 2021

The problem

When trying to add the new, fixed, Tesla integration I get: "Unknown error occurred". I have removed the old Tesla integration and restarted HA, but still the same error.

What is version of Home Assistant Core has the issue?

core-2021.2.3

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

tesla

Link to integration documentation on our website

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

Example YAML snippet

# Put your YAML below this line

Anything in the logs that might be useful for us?

# Put your logs below this line
Logger: aiohttp.server
Source: components/tesla/config_flow.py:157
First occurred: 3:31:47 PM (2 occurrences)
Last logged: 3:39:29 PM

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 118, 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 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 169, 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 106, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 155, 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 213, 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 157, 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
@probot-home-assistant
Copy link

Hey there @zabuldon, @alandtse, mind taking a look at this issue as its been labeled with an integration (tesla) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@3mta3
Copy link

3mta3 commented Feb 11, 2021

I had the same issue after the .3 patch - disabled 2fA on my Tesla account and was able to add the integration no problem. fwiw and fyi.

@oscfor
Copy link
Author

oscfor commented Feb 11, 2021

Yes, I am using 2FA. Maybe there should be a warning that the integration doesn’t work if you utilize 2FA.

@alandtse
Copy link
Contributor

Yes, MFA is unsupported. Feel free to update the documentation to indicate that. I'm working on a separate fix but it may not arrive for a while.

The workaround others have been using is creating a separate account for HA to use itself without MFA. I'll probably put in a short term fix to make it an appropriate error message.

@oscfor
Copy link
Author

oscfor commented Feb 11, 2021

Thanks for the update! Unfortunately the workaround is not possible for me because one of my cars is just an invite.

I have updated the documentation.

@MindFreeze
Copy link

I get this error even without MFA. Tried 2 accounts already.

@carfnann
Copy link

Hi

My Tesla integration was not working anymore, I've deleted the integration but I'm not able to add it again. "Failed to connect"
I'm not using 2FA...

@SweNilsson
Copy link

SweNilsson commented Feb 12, 2021

After deletion and reboot I got it working. Mind the long update time, so you can't expect data to be collected directly if you don't set "wake on start-up".

@MindFreeze
Copy link

I've deleted the integration and can't add it back even after many restarts and 2 different accounts without MFA.
Error I get in the log is the same as OP:

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 118, 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/forwarded.py", line 71, in forwarded_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 72, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 127, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 129, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 169, 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 106, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 155, 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 213, 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 157, 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

@k1n6b0b
Copy link

k1n6b0b commented Feb 14, 2021

FYI I read on another site that Tesla deprecated user login for API access and now requires token generation - could that be related?

Edit: v2 Tokens are deprecated as of 29 JAN | reference post on API v3 from teslafi https://support.teslafi.com/en/communities/1/topics/16979-tesla-v3-api-tokens

are we using v2?

Edit again: Yes @tbeloc that was my issue (sheepish) I was on 2021.2.2

Release 2021.2.3 - February 11
Use oauthv3 for Tesla (@alandtse - #45766) (tesla docs) (breaking-change)

I'm all good now!

@alandtse
Copy link
Contributor

I have a potential fix for MFA that needs testing by advanced users in the linked PR. If you cannot figure out how to apply it yourself safely, please consider waiting till it's released. I will be fixing any bugs discovered but not to be too harsh, I won't be responding to questions on how to apply it.

@tbeloc
Copy link

tbeloc commented Feb 16, 2021

I had the same problem, I upgraded to the latest version and it works.

@dennisbrouwer91
Copy link

Any update on releasing this ?

@alandtse
Copy link
Contributor

For those who want to have help installing pending PRs for testing, I just released a custom component that helps simplify it. I am currently using that to use my PR in my production system because I enabled 2FA and apparently I can't figure out how to remove it from my account.

@3mta3
Copy link

3mta3 commented Apr 17, 2021

Appears the error is back - was working fine with 2FA disabled, began receiving 'tuple index errors', uninstalled the integration and can't add it back (won't accept credentials). I think my error is the same as @oscfor:

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

@stepir
Copy link

stepir commented Apr 18, 2021

+1 was working fine then 'tuple index error' removed and can't add it back (same error as above)

@zephyrus9MA
Copy link

zephyrus9MA commented Apr 18, 2021

+1 Core 2021.4.5. Used an earlier snapshot with Tesla integration installed. Same log messages and all data "unavailable".

@benschwartz42
Copy link

+1 Core 2021.4.5 seeing this issue as well

@akiro
Copy link

akiro commented Apr 19, 2021

+1, same here, tesla integration stopped working after upgrade to 2021.4.5. Tried removing it and re-adding it, "unknown error occured".

@Schelin78
Copy link

Stopped working today 😥

@iancg
Copy link

iancg commented Apr 20, 2021

Also stopped working today - no MFA.

For me it may have been co-incident with an upgrade to 2021.4.6 from 2021.4.5, but in fairness I hadn't checked for this before the upgrade, so it could have just been waiting to fail on the next restart.

@DavidDeSloovere
Copy link
Contributor

2021.4.6 still has this error, re-adding integration won't help/work

IndexError: tuple index out of range

@davispeden1
Copy link

davispeden1 commented Apr 20, 2021

I rolled back to 2021.4.3 from 2021.4.6 via snapshot restore and the issue went away. Going to hang here for a bit.

I have a separate Tesla account I use for HA and 2fa is not enabled. My config has been solid since early January.

EDIT...take that back. It worked for a few minutes and then stopped working.

@davispeden1
Copy link

Debug log attached. Captured this right after restarting HA. Hoping someone can make some sense of it.

HATeslaDebugLog-04-20-2021.txt

@davispeden1
Copy link

Another debug log attached. I captured this one after removing the integration, restarting HA and then attempting to add again from the UI. Within the UI, I got an "Unknown error occurred" message when adding my email and password. Attached are the corresponding debug logs.

HATeslaDebugLog - Attempt to add integration after removal-04-20-2021.txt

@stepir
Copy link

stepir commented Apr 20, 2021

I rolled back to 2021.4.3 from 2021.4.6 via snapshot restore and the issue went away. Going to hang here for a bit.

I have a separate Tesla account I use for HA and 2fa is not enabled. My config has been solid since early January.

EDIT...take that back. It worked for a few minutes and then stopped working.

yeah I'm running CORE 2021.2.3 and the integration stopped working w/o any updates

@skynet01
Copy link

Could this be related to that v2 Tokens are deprecated as of 29 JAN? here are the details on this https://support.teslafi.com/en/communities/1/topics/16979-tesla-v3-api-tokens

@fcastilloec
Copy link

@skynet01 I don't think that's the problem. See cdd7831, where support for v3 tokens was introduced (by updating teslajsonpy, the python library this integration uses).
Probably what might fix this issue is updating teslajsonpy to the latest version, which includes a few bug fixes and also has support for MFA.

@Verguldebarman
Copy link

Verguldebarman commented Apr 22, 2021

I'm on Home Assistant 2021.4.6, same issue: IndexError: tuple index out of range

Removed Tesla integration, restarted HA and tried to reinstall Tesla integration: Unknown error occurred.

image

@slee29
Copy link

slee29 commented Apr 23, 2021

I'm on Home Assistant 2021.4.6, same issue: IndexError: tuple index out of range

Removed Tesla integration, restarted HA and tried to reinstall Tesla integration: Unknown error occurred.

image

Same exact situation for myself.

@alandtse
Copy link
Contributor

@skynet01 I don't think that's the problem. See cdd7831, where support for v3 tokens was introduced (by updating teslajsonpy, the python library this integration uses).
Probably what might fix this issue is updating teslajsonpy to the latest version, which includes a few bug fixes and also has support for MFA.

You are correct. We already have oauth v3 tokens in teslajsonpy. We also have an explicit check on the tuple error people are seeing so updates will get a different error. However, that check won't necessarily help because Tesla is returning a 403 forbidden on the auth page. I'm stumped and so are others on why because it's random on which systems see it. You can try the closed PR and it may work for you. Or it might not.

@denisjoshua
Copy link

I subscribe cause I have same error.
Thanks

@ukmgranger
Copy link

I'm getting the same errors as others - 'unknown error occurred'.

@robpow
Copy link

robpow commented Apr 25, 2021

I have nothing more to add apart from what's already been stated, the exact same problem here.

@rudyo85
Copy link

rudyo85 commented Apr 26, 2021

Same problem overhere, will follow this thread for a solution

@jackknife76
Copy link

Following for updates

@MindFreeze
Copy link

FFS. You don't need to comment in order to follow. And we know everyone has the same problem. I don't need to receive an email every time someone realizes their integration doesn't work.

Comments are for contributions to a solution. If you don't have any new debug info. Use the subscribe button and the reaction emojis.

@stepir
Copy link

stepir commented Apr 28, 2021

zabuldon/teslajsonpy#190

resolved and being repackaged in the next days. Kudos to @alandtse

Ppl: https://www.buymeacoffee.com/alandtse

@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.

@NicklasMD
Copy link

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.

Does it work with MFA also?

/Nicklas

@oscfor
Copy link
Author

oscfor 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.

Does it work with MFA also?

/Nicklas

Yes! Just set it up. Works like a charm.

@abuchanan920
Copy link

Is this going to be fixed in core as well? Or do we need to migrate to the custom component?

@DavidDeSloovere
Copy link
Contributor

AFAIK the workaround for authentication will not be accepted in HA Core. See #46558 (comment)
So unless Tesla offers a public API will full support for 3rd party applications, you'll need to keep using the custom component.

@dancrevier
Copy link

There are 2 issues. One affects all auth and has been integrated into 2021.5 (#49939). The other affects only MFA and it looks like that won't be integrated because of the web scraping. So, if you aren't using MFA, things should be fixed with this month's release.

@alandtse
Copy link
Contributor

alandtse commented May 2, 2021

Correct, we just merged in #49939 which will allow regular logins without MFA. However, MFA will not work unless you go to the custom component until someone implements it. I do not plan on doing that.

@bdraco bdraco closed this as completed May 2, 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

No branches or pull requests