Skip to content

double-encoding of json response results in TypeError: string indices must be integers, not 'str' #174

@cjw296

Description

@cjw296

This looks like a change in Tesla API responses over the last couple of weeks as this has been working fine for a year or two now without change on my end...

My code does:

battery.set_tariff(required_tariff)

This results in a POST to https://owner-api.teslamotors.com/api/1/energy_sites/2444871/time_of_use_settings, but what comes back nows is:

'{"response":"{\\"Message\\":\\"Updated\\",\\"Code\\":201}\\n"}'

Note the response is now a string containing json, so it would need to be decoded again, but in the meantime this happens:

    self.battery.set_tariff(required_tariff)
  File "/python3.12/site-packages/teslapy/__init__.py", line 869, in set_tariff
    return self.command('TIME_OF_USE_SETTINGS',
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.12/site-packages/teslapy/__init__.py", line 804, in command
    if response['code'] == 201:
       ~~~~~~~~^^^^^^^^
TypeError: string indices must be integers, not 'str'

Anyone else seen this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions