tdorssers / TeslaPy

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

No connection adapters were found for #97

Closed gi11es closed 2 years ago

gi11es commented 2 years ago

I've moved my code to a new host, and now I get this for POST commands:

Traceback (most recent call last):
  File "/home/freebox/tesla2.py", line 228, in <module>
    vehicles[0].command('START_CHARGE')
  File "/home/freebox/.local/lib/python3.10/site-packages/teslapy/__init__.py", line 703, in command
    response = self.api(name, **kwargs).get('response')
  File "/home/freebox/.local/lib/python3.10/site-packages/teslapy/__init__.py", line 482, in api
    return self.tesla.api(name, {'vehicle_id': self['id_s']}, **kwargs)
  File "/home/freebox/.local/lib/python3.10/site-packages/teslapy/__init__.py", line 363, in api
    return self.request(endpoint['TYPE'], uri, serialize,
  File "/home/freebox/.local/lib/python3.10/site-packages/teslapy/__init__.py", line 147, in request
    response = super(Tesla, self).request(method, url, **kwargs)
  File "/home/freebox/.local/lib/python3.10/site-packages/requests_oauthlib/oauth2_session.py", line 521, in request
    return super(OAuth2Session, self).request(
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 649, in send
    adapter = self.get_adapter(url=request.url)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 742, in get_adapter
    raise InvalidSchema("No connection adapters were found for {!r}".format(url))
requests.exceptions.InvalidSchema: No connection adapters were found for 'https://owner-api.teslamotors.com/api/1/vehicles/**my_vehicle_id**/command/charge_start'

I'm running 2.6.0 installed from pip3, python 3.10.4. requests_oauthlib is version 1.3.1

I removed cache.json just in case and redid the authentication, I still get the same error.

The GET commands are working fine, I'm getting vehicle data, etc. But POST commands result in this error.

It's possible that the host move is unrelated to the bug, as I hadn't run the code on the old host for a few weeks prior to the move.

gi11es commented 2 years ago

It seems like close() is getting called prematurely on the Tesla class, which nukes self.adapters. I'll try to track down why.

gi11es commented 2 years ago

Nevermind, this was user error on my part. An identation bug in my code where the POST commands were not in the "with teslapy.Tesla" block they should have been in. I guess maybe an older version of the library didn't do the self.adapters cleanup and that's what I was using on the old host?

gi11es commented 2 years ago

Yep, I see that this cleanup code was added in 2.6.0, I was probably running 2.5.0 on the old host. So the code in my bug was hidden by the fact that the self.adapters cleanup wasn't happening.