mlowijs / tesla_api

Lightweight Python API client for the Tesla API.
MIT License
80 stars 31 forks source link

Deprecated endpoint #36

Closed scienceintheshed closed 3 years ago

scienceintheshed commented 3 years ago

It appears that one of the endpoints to get info from list_energy_sites() endpoint has been deprecated.

# Simple code to demonstrate problem

from tesla_api import TeslaApiClient
from datetime import datetime
import time

now = datetime.now()
print(now)
print("Starting Tesla5 program...")

client = TeslaApiClient("username", "password")

energy_sites = client.list_energy_sites()
print("Number of energy sites = %d" % (len(energy_sites)))
assert(len(energy_sites)==1)

# Output

==================== RESTART: C:/Python/Powerwall/Tesla5B.py ===================
2021-01-30 10:28:55.929762
Starting Tesla5 program...
Traceback (most recent call last):
  File "C:/Python/Powerwall/Tesla5B.py", line 11, in <module>
    energy_sites = client.list_energy_sites()
  File "C:/Python/Powerwall\tesla_api\__init__.py", line 94, in list_energy_sites
    return [Energy(self, products['energy_site_id']) for products in self.get('products')]
  File "C:/Python/Powerwall\tesla_api\__init__.py", line 69, in get
    self.authenticate()
  File "C:/Python/Powerwall\tesla_api\__init__.py", line 55, in authenticate
    self._token = self._get_new_token()
  File "C:/Python/Powerwall\tesla_api\__init__.py", line 33, in _get_new_token
    raise AuthenticationError(response_json['response'])
tesla_api.AuthenticationError: Authentication to the Tesla API failed: endpoint_deprecated:_please_update_your_app.
>>>
Dreamsorcerer commented 3 years ago

Feel free to make a PR if you know how to update it. I don't have solar or powerwall to test this myself.

scienceintheshed commented 3 years ago

Problem is I'm not sure what's broken...still trying to work it out.

Dreamsorcerer commented 3 years ago

Actually, I misread the traceback. I think they must have disabled the password login.

Therefore this is probably a duplicate of #31.

ngardiner commented 3 years ago

Tesla have disabled the v2 authentication endpoint, meaning that v3 / MFA flow is now required:

https://github.com/timdorr/tesla-api/issues/215

Dreamsorcerer commented 3 years ago

As I suspected. Closing as duplicate of #31.

scienceintheshed commented 3 years ago

Thanks, have started following. Hopefully someone will post a fix as I have a few scripts that are now broken.

Dreamsorcerer commented 3 years ago

If nobody else has a go at it, I'm sure I'll get round to it in a few weeks.