tdorssers / TeslaPy

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

TypeError: unsupported format string passed to NoneType.__format__ #118

Open cycl0ne opened 1 year ago

cycl0ne commented 1 year ago

HI,

treid your little programs. the menu.py threw me this:

Traceback (most recent call last): File "/home/pos/python/./menu.py", line 347, in main() File "/home/pos/python/./menu.py", line 326, in main menu(vehicles[idx]) File "/home/pos/python/./menu.py", line 180, in menu show_vehicle_data(vehicle.get_vehicle_data()) File "/home/pos/python/./menu.py", line 75, in show_vehicle_data print(fmt.format(door.get(ve['ft']), door.get(ve['rt']))) TypeError: unsupported format string passed to NoneType.format

cycl0ne commented 1 year ago

Ok seems there are more errors coming in.. on my second vehicle (MYC) : VIN decode: Tesla Motors, Inc., Tesla Model Y, Class D MPV / 5 Dr / LHD, Type 2 manual seatbelts (FR, SR2, TR2) with front airbags, PODS, side inflatable restraints, knee airbags (FR), Electric (NMC), Unknown, 2022, Shanghai, China Traceback (most recent call last): File "/home/pos/python/./menu.py", line 347, in main() File "/home/pos/python/./menu.py", line 324, in main print('Option codes:', ', '.join(vehicles[idx].option_code_list())) File "/home/poos/.local/lib/python3.9/site-packages/teslapy/init.py", line 540, in option_code_list for code in self['option_codes'].split(',')])) AttributeError: 'NoneType' object has no attribute 'split'

cycl0ne commented 1 year ago

Oh and another Question, while im trying to understand how to use the class:

import teslapy
tesla = teslapy.Tesla('claus@poweros.de')
if not tesla.authorized:
    print('Use browser to login. Page Not Found will be shown at success.')
    print('Open this URL: ' + tesla.authorization_url())
    tesla.fetch_token(authorization_response=input('Enter URL after authentication: '))
vehicles = tesla.vehicle_list()
vehicles[0].sync_wake_up()
print(vehicles[0]['charge_state'])
tesla.close()

Allways dumps me everything 0?? { "battery_heater_on": false, "battery_level": 0, "battery_range": 0.0, "charge_current_request": 0, "charge_current_request_max": 0, "charge_enable_request": false, "charge_energy_added": 0.0, "charge_limit_soc": 0, "charge_limit_soc_max": 0, "charge_limit_soc_min": 0, "charge_limit_soc_std": 0, "charge_miles_added_ideal": 0.0, "charge_miles_added_rated": 0.0, "charge_port_cold_weather_mode": false, "charge_port_color": "Off", "charge_port_door_open": false, "charge_port_latch": "Engaged", "charge_rate": 0, "charge_to_max_range": false, "charger_actual_current": 0, "charger_phases": 0, "charger_pilot_current": 0, "charger_power": 0, "charger_voltage": 0, "charge_amps": 0, "charging_state": "Disconnected", "conn_charge_cable": "IEC", "est_battery_range": 0.0, "fast_charger_brand": "SNA", "fast_charger_present": false, "fast_charger_type": "Supercharger", "ideal_battery_range": 0.0, "managed_charging_active": false, "managed_charging_start_time": 0, "managed_charging_user_canceled": false, "max_range_charge_counter": 0, "minutes_to_full_charge": 0, "time_to_full_charge": 0.0, "not_enough_power_to_heat": false, "off_peak_charging_enabled": false, "off_peak_charging_times": "all_week", "off_peak_hours_end_time": 0, "preconditioning_enabled": false, "preconditioning_times": "all_week", "scheduled_charging_mode": "Off", "scheduled_charging_pending": false, "scheduled_charging_start_time": 0, "scheduled_charging_start_time_app": 0, "scheduled_charging_start_time_minutes": 0, "scheduled_departure_time_minutes": 0, "supercharger_session_trip_planner": false, "timestamp": 1672913759730, "trip_charging": false, "usable_battery_level": 0, "user_charge_enable_request": false }

tdorssers commented 1 year ago

I can't reproduce these errors and I have never seen all zero's returned by the API. Does cli.py work for you? Can you do python cli.py -e claus@poweros.de -w -g?

cycl0ne commented 1 year ago

Ok, the cli.py works smoothless. all values are there. I tried this again after the successful cli.py

import teslapy
tesla = teslapy.Tesla('claus@poweros.de')
if not tesla.authorized:
    print('Use browser to login. Page Not Found will be shown at success.')
    print('Open this URL: ' + tesla.authorization_url())
    tesla.fetch_token(authorization_response=input('Enter URL after authentication: '))
vehicles = tesla.vehicle_list()
vehicles[1].sync_wake_up()
print(vehicles[1]['charge_state'])
tesla.close()

Everything is 0... "battery_heater_on": false, "battery_level": 0, "battery_range": 0.0, "charge_current_request": 0, "charge_current_request_max": 0, "charge_enable_request": false, "charge_energy_added": 0.0, "charge_limit_soc": 0, "charge_limit_soc_max": 0, "charge_limit_soc_min": 0, "charge_limit_soc_std": 0,

If i start cli.py again.. all values are there.. hmm... where is the bug in this short code? :-)


Another Question, when i issue a -u: python3 teslacli.py -e claus@poweros.de -u

2023-01-09 07:01:14,814 - root - INFO - 2 product(s), 2 selected Product 0: Traceback (most recent call last): File "/home/pos/python/teslacli.py", line 180, in main() File "/home/pos/python/teslacli.py", line 116, in main print(product.get_user_details()) File "/home/pos/.local/lib/python3.9/site-packages/teslapy/init.py", line 580, in get_user_details return self.tesla.api('USER_ACCOUNT_GET_DETAILS', vin=self['vin'], File "/home/pos/.local/lib/python3.9/site-packages/teslapy/init.py", line 369, in api return self.request(endpoint['TYPE'], uri, serialize, File "/home/pos/.local/lib/python3.9/site-packages/teslapy/init.py", line 158, in request response.raise_for_status() # Raise HTTPError, if one occurred File "/usr/lib/python3/dist-packages/requests/models.py", line 943, in raise_for_status raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://owner-api.teslamotors.com/bff/v2/mobile-app/account/details?vin=5YJ3E7EB6MF831849&deviceCountry=US&deviceLanguage=EN

deviceCountry=US -> Maybe this? im located in DE...

cycl0ne commented 1 year ago

Ok maybe found something. in the Example you write: -> automatically calls get_latest_vehicle_data() when a key is not found.

This isnt done. My small script works if i change to this:

vehicles = tesla.vehicle_list()
vehicles[1].sync_wake_up()
vehicles[1].get_vehicle_data()
print(vehicles[1]['charge_state'])
tesla.close()

And this is why cli.py works. It calls the get_verhicle_data...

gbizeau commented 1 year ago

Do you have two Teslas? Because you're gathering data from vehicles[1], instead of vehicles[0]?

On Mon, Jan 9, 2023 at 3:52 AM Claus Herrmann @.***> wrote:

Ok maybe found something. in the Example you write: -> automatically calls get_latest_vehicle_data() when a key is not found.

This isnt done. My small script works if i change to this:

vehicles = tesla.vehicle_list() vehicles[1].sync_wake_up() vehicles[1].get_vehicle_data() print(vehicles[1]['charge_state']) tesla.close()

Cheers C.

— Reply to this email directly, view it on GitHub https://github.com/tdorssers/TeslaPy/issues/118#issuecomment-1375220084, or unsubscribe https://github.com/notifications/unsubscribe-auth/A22GEVD6OUI4WZLNJ7P3YF3WRO7TDANCNFSM6AAAAAATQQG4XA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

cycl0ne commented 1 year ago

Yes correct. Got two Teslas and allways trying 0 and 1 just to check if both behave same.

tdorssers commented 1 year ago

It seems that USER_ACCOUNT_GET_DETAILS is no longer available.

tdorssers commented 1 year ago

Latest commit should fix the option list TypeError, as vehicle options are now None.