Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teslajsonpy.exceptions.TeslaException: HTTP 406: not_a_JSON_request #231

Closed
paracetamol32 opened this issue Jul 9, 2022 · 6 comments
Closed
Labels
bug Something isn't working teslajsonpy Issue with dependency

Comments

@paracetamol32
Copy link

Version of the custom_component

2.0.0

Configuration

Describe the bug

Today, the service api is broken.
when calling api i have tis result: Call-service error
No problem before

Step to reproduce:

go in developper tools - > service.
Call service tesla custom api:

service: tesla_custom.api
data:
command: CHARGING_AMPS
parameters:
path_vars:
vehicle_id: '{{ state_attr(''binary_sensor.re_volt_online_sensor'', ''id'') }}'
charging_amps: 15

@IIDemoniaKII
Copy link

IIDemoniaKII commented Jul 9, 2022

Hello,

Same here since update 2022.7.2

Good luck

Edit :

It seems that it only concerns : CHARGING_AMPS

The following commands work fine :

  • WAKE_UP
  • START_CHARGE
  • STOP_CHARGE
  • CLIMATE_ON
  • CLIMATE_OFF

Call :

service: tesla_custom.api
data:
  command: CHARGING_AMPS
  parameters:
    path_vars:
      vehicle_id: '{{ state_attr(''binary_sensor.stacy_online_sensor'', ''id'') }}'
    charging_amps: >-
      {% if states("sensor.stacy_charging_amps") | int(0) | int(0) <= 0 %}  0
      {%- else -%} {{ states("sensor.stacy_charging_amps") | int(0) }} {%- endif
      %}

results :

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/script/__init__.py", line 428, in _async_run
    return await self.script.async_run(script_vars, context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1513, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 405, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 449, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 472, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/tesla_custom/services.py", line 56, in async_call_tesla_service
    await api(service_call)
  File "/config/custom_components/tesla_custom/services.py", line 112, in api
    return await controller.api(name=command, path_vars=path_vars, **parameters)
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/controller.py", line 183, in wake_up
    result = await wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/controller.py", line 1803, in api
    return await self.__connection.post(
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/connection.py", line 164, in post
    return await self.__open(url, method=method, headers=self.head, data=data)
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/connection.py", line 213, in __open
    raise TeslaException(resp.status_code)
teslajsonpy.exceptions.TeslaException
Tesla - Puissance recharge = Consigne automatique: Error executing script. Unexpected error for call_service at pos 1:
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/tesla_custom/services.py", line 56, in async_call_tesla_service
    await api(service_call)
  File "/config/custom_components/tesla_custom/services.py", line 112, in api
    return await controller.api(name=command, path_vars=path_vars, **parameters)
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/controller.py", line 183, in wake_up
    result = await wrapped(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/controller.py", line 1803, in api
    return await self.__connection.post(
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/connection.py", line 164, in post
    return await self.__open(url, method=method, headers=self.head, data=data)
  File "/usr/local/lib/python3.10/site-packages/teslajsonpy/connection.py", line 213, in __open
    raise TeslaException(resp.status_code)
teslajsonpy.exceptions.TeslaException

@lcorreia007
Copy link

lcorreia007 commented Jul 9, 2022

Same here, also after updating to 2022.7.2
Could be related to 2022.7 bump of python version to 3.10

@RicSuzu
Copy link

RicSuzu commented Jul 9, 2022

I am still on version 2022.6.4 and CHARGING_AMPS stopped working for me yesterday.

@simonwestenholz
Copy link

simonwestenholz commented Jul 9, 2022

I can’t make it do much of anything. Open trunk, flash lights, set charge limit, etc. all return the following error from the teslajsonpy debug log:

2022-07-09 17:59:06 DEBUG (MainThread) [teslajsonpy.connection] post: https://owner-api.teslamotors.com/api/1/vehicles/{ID}/command/actuate_trunk {'which_trunk': 'rear'}
2022-07-09 17:59:06 DEBUG (MainThread) [teslajsonpy.connection] 406: {"response":null,"error":"not_a_JSON_request","error_description":""}
2022-07-09 17:59:06 DEBUG (MainThread) [teslajsonpy.controller] Exception: 
api(('ACTUATE_TRUNK',) {'path_vars': {'vehicle_id': {ID}}, 'which_trunk': 'rear', 'wake_if_asleep': True})

The "not_a_JSON_request" is odd to me...

@alandtse
Copy link
Owner

alandtse commented Jul 9, 2022

It's probably a Tesla API change. Until someone figures out a solution, there may be nothing to do except avoiding hammering Tesla's servers and getting blocked. timdorr/tesla-api#594

@bojihao
Copy link

bojihao commented Jul 10, 2022

I updated the file at /usr/local/lib/python3.9/site-packages/teslajsonpy/connection.py in my HA docker by changing line 200 from str(url), data=data, headers=headers, cookies=cookies to str(url), json=data, headers=headers, cookies=cookies and everything seems to be working again.

@alandtse alandtse changed the title tesla_custom.api is dead teslajsonpy.exceptions.TeslaException: HTTP 406: not_a_JSON_request Jul 10, 2022
@alandtse alandtse added bug Something isn't working teslajsonpy Issue with dependency labels Jul 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working teslajsonpy Issue with dependency
Projects
None yet
Development

No branches or pull requests

7 participants