ianjwhite99 / connected-car-python-sdk

Open-source Python SDK for Ford vehicles connected with Sync Connect (Ford Pass)
MIT License
71 stars 12 forks source link

connectedcar.exceptions.SyncException: Unexpected error #76

Open nils2410 opened 1 year ago

nils2410 commented 1 year ago

Hi, i got the following error: connectedcar.exceptions.SyncException: Unexpected error

Code:

import connectedcar

client = connectedcar.AuthClient(
    '9fb503e0-715b-47e8-adfd-ad4b7770f73b',
    None,
    None,
    None,
    'EU')  # Create client connection

access = client.get_user_access_token(
    'mail@domain.com', 'asdf1234')

vehicle = connectedcar.Vehicle('WXXXXXXXXX12345', access['access_token'], "EU")  # Create vehicle object

print(vehicle.details())

Output:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/requester.py", line 35, in call
    raise E.ResourceNotFoundException(response)
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/exceptions.py", line 9, in __init__
    json = response.json()
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/dist-packages/simplejson/decoder.py", line 373, in decode
    raise JSONDecodeError("Extra data", s, end, len(s))
simplejson.errors.JSONDecodeError: Extra data: line 1 column 5 - line 2 column 1 (char 4 - 94)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "fordpass2openhab.py", line 27, in <module>
    print(vehicle.details())
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/vehicle.py", line 104, in details
    '/detail?lrdt=01-01-1970%2000:00:00')
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/api.py", line 68, in get
    return requester.call('GET', url, headers=headers)
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/requester.py", line 49, in call
    raise E.SyncException("Unexpected error") from e
connectedcar.exceptions.SyncException: Unexpected error

The following code works and shows my vehicles, the problem occurs by calling connectedcar.Vehicle.

user = connectedcar.User(access['access_token'], "EU")
vehicles = user.vehicles()  # Fetch list of user vehicles

Does anyone know a solution?

ianjwhite99 commented 1 year ago

Hi @nils2410,

Try switching your region to "US". Sometimes there are issues with authenticating in different regions. Let me know if that solution works for you.

nils2410 commented 1 year ago

i changed the region to US:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/requester.py", line 37, in call
    raise E.ResourceNotFoundException(response)
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/exceptions.py", line 9, in __init__
    json = response.json()
  File "/usr/local/lib/python3.7/dist-packages/requests/models.py", line 900, in json
    return complexjson.loads(self.text, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/simplejson/__init__.py", line 525, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.7/dist-packages/simplejson/decoder.py", line 373, in decode
    raise JSONDecodeError("Extra data", s, end, len(s))
simplejson.errors.JSONDecodeError: Extra data: line 1 column 5 - line 2 column 1 (char 4 - 94)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "fordpass2openhab.py", line 27, in <module>
    print(vehicle.details())
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/vehicle.py", line 104, in details
    '/detail?lrdt=01-01-1970%2000:00:00')
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/api.py", line 68, in get
    return requester.call('GET', url, headers=headers)
  File "/usr/local/lib/python3.7/dist-packages/connectedcar/requester.py", line 51, in call
    raise E.SyncException("Unexpected error") from e
connectedcar.exceptions.SyncException: Unexpected error``

response.text returns the following error: 404 Not Found: Requested route ('user-profile-proxy-prod.uspd01.cf.ford.com') does not exist.

budwazzer commented 1 year ago

Login works fine, but there is a problem in details() in vehicle.py but status() works fine.

getData.py `import connectedcar from datetime import datetime

client = connectedcar.AuthClient( '9fb503e0-715b-47e8-adfd-ad4b7770f73b', None, None) # Create client connection access = client.get_user_access_token( 'email', 'password') # Fetch client access token

user = connectedcar.User(access['access_token']) # New User Object vehicles = user.vehicles() # Fetch list of user vehicles

vehicleList = [] # Stored list of user vehicles

for userVehicle in vehicles: # For each user vehicle vehicleList.insert(0, userVehicle['VIN']) break

def ukaz(co): currentVehicle = connectedcar.Vehicle( vehicleList[0], access['access_token']) # IF YOU HAVE MORE CARS, THIS USE 1st [0]. a = datetime.today() funkce = ("currentVehicle." + co + "()") print ("") print ("--- {} - -->".format(co)) print(eval(funkce)) # Send command b = datetime.today() sekund = ((b-a).total_seconds()) print ("<--- {} - {} s".format(co,sekund))

ukaz("odometer") ukaz("fuel")

and so on...`

I've been stuck on this for months but finally found the time to go through the code. It's a little thing, I believe the author will fix it easily when he has time. But it still works great for me. Thank you @ianjwhite99 for great work.