Closed SylvainGa closed 2 years ago
You can try to enable retries, so requests will retry after a connection aborted exception:
with teslapy.Tesla(username, retry=3, timeout=20) as tesla:
You can even have TeslaPy retry HTTP exceptions:
retry = teslapy.Retry(total=3, status_forcelist=(500, 502, 503, 504)) with teslapy.Tesla(username, retry=retry, timeout=20) as tesla:
Thanks, I'll give it a try.
No crash today with the addition of the retry and timeout parameters. I'll report back tomorrow and close the issue if all is well, thanks.
Great. The reason that retries aren't enabled by default, is that if you hammer the API too much, your account can be blocked temporarily. But if you retry a couple of times and back off a while and retry again, then it shouldn't be an issue.
Hi, it crashed again reading the following line:
vehicleData = vehicles[vehicle].get_vehicle_data()
With a 408 exception. The line just before that was
if vehicles[vehicle].available() == True: # Only read if the car isn't asleep
From what I got in your doc for 'available':
checks if the vehicle is online based on cached data or refreshed status when aged out
It looks like the car went offline before the cache aged out.
I'm just starting with Python and not sure I would go about forcing a cache refresh before the 'available()' call or adding a HTTPError 408 exception around that 'get_vehicle_data()' so it acts as if the car is offline when it's thrown.
For now, i'm doing my own 'available' check as such
available = False
vehicles = tesla.vehicle_list()
if vehicles[vehicle]['state'] != 'asleep':
available = True
Wondering if there is a better way.
Thanks,
I would catch the 408 exception, because it takes about 30 seconds for the car to actually go to sleep.
Thanks, I've set the retry and connection parameters as such
retry = teslapy.Retry(total=5, status_forcelist=(408, 500, 502, 503, 504, 540)) tesla = teslapy.Tesla(Config.get('Tesla', 'username'), retry=retry, timeout=10)
I'll see how it goes in the following days. Thanks for maintaining this library btw :-)
Has been stable since my last post 5 days ago. I'll go ahead and close this issue. Thanks for your help :-)
I do wish Tesla would implement internally what I'm doing here, which is when rain is detected (it does already), close the windows if the car is parked. Could work similar to cabin overheat protection. It would work everywhere, not just close to my weather station.
Working, thanks for your help.
Got the following crash this morning. I've 'bolded' the line that I think in my source code generated the crash. I'm using a refresh token to connect. It runs without issue for several hours. Not sure if it's about the access token expiring. The next expiration is today at 11:02:00 PM local time. I'll see if it does it then.
The source is at https://github.com/SylvainGa/TeslaRainCheck