tdorssers / TeslaPy

A Python module to use the Tesla Motors Owner API
MIT License
374 stars 83 forks source link

Commands Hanging On New Ubuntu Installation #78

Closed Haselmaier closed 2 years ago

Haselmaier commented 2 years ago

I've been using Teslapy for about 6 months. Awesome. I use it to adjust charging based on solar panel output.

I recently built up an Ubuntu machine. The code hangs when executing a command. See the attached output when I stop the code. This code runs on other machines (e.g. Windows) but won't run on this Ubuntu machine.

All the packages identified in requirements.txt seem to be up to minimum versions required.

Any guidance on what I need to do to rectify this?

Thanks.

Jim Haselmaier Suncatcher

tdorssers commented 2 years ago

Are you using different versions of TeslaPy on your machines? This requests exception probably occurs because the Tesla instance is accessed outside of the context manager. Recent versions of TeslaPy destroy the connection adapter when the context manager exits.

Haselmaier commented 2 years ago

Thanks Tim.

The other machines were on 2.2.0 and the Ubuntu machine was running 2.5.0.

I put 2.2.0 on the Ubuntu machine and all seems fine now.

Thanks so much!

Jim

tdorssers commented 2 years ago

Maybe these two examples help. A context manager automatically closes the requests session. TeslaPy 2.5.0 also closes the connection adapter. This has been done because the requests module doesn't reconnect on network failures once it has been closed. So for long running scripts TeslaPy 2.5.0 is the recommended version.

With context manager:

with teslapy.Tesla('elon@tesla.com') as tesla:
    vehicles = tesla.vehicle_list()
    vehicles[0].command('FLASH_LIGHTS')
vehicles[0].command('FLASH_LIGHTS')  # Causes exception

Without context manager:

tesla = teslapy.Tesla('elon@tesla.com')
vehicles = tesla.vehicle_list()
vehicles[0].command('FLASH_LIGHTS')
tesla.close()
vehicles[0].command('FLASH_LIGHTS')  # Causes exception