ianjwhite99 / connected-car-python-sdk

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

connectedcar.exceptions.ValidationException: Unknown error #72

Closed dixkxnsks closed 1 year ago

dixkxnsks commented 1 year ago

I get this error (connectedcar.exceptions.ValidationException: Unknown error) after vehicles = user.vehicles(). Complete code:

import connectedcar

client = connectedcar.AuthClient('9fb503e0-715b-47e8-adfd-ad4b7770f73b', None, None, None, 'EU')
access = client.get_user_access_token('email', 'password')
refreshToken = client.exchange_refresh_token(access['refresh_token'])
user = connectedcar.User(access['access_token'], "EU")
vehicles = user.vehicles()

vehicleList = []

for userVehicle in vehicles:
    vehicleList.append(userVehicle['VIN'])

currentVehicle = connectedcar.Vehicle(vehicleList[0], access['access_token'], "EU")
print(currentVehicle.status())
ianjwhite99 commented 1 year ago

@dixkxnsks If you switch from "EU" to "US" region are you still encountering this error trying to access vehicles = user.vehicles()?

The new vehicles endpoint requires the locale and countryCode parameters to be set in the request headers. The country code should be fine but the locale may be incorrect.

By default I have the locale set to en-US, which is probably why you are experiencing an error making a request to get the user vehicles. (See below)

/src/Api/Api.ts

constructor(accessToken: string, region: string, locale = 'en-US') {
    const regions = {
      US: '71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592',
      CA: '71A3AD0A-CF46-4CCF-B473-FC7FE5BC4592',
      EU: '1E8C7794-FF5F-49BC-9596-A1E0C86C5B19',
      AU: '5C80A6BB-CF0D-4A30-BDBF-FC804B5C1A98',
    };

    const countryCode = {
      US: 'USA',
      CA: 'CAN',
      EU: 'EUR',
      AU: 'AUS',
    };

    this.headers = {
      'auth-token': accessToken,
      Accept: '*/*',
      'Accept-Language': 'en-US',
      'User-Agent': 'FordPass/24 CFNetwork/1399 Darwin/22.1.0',
      'Content-Type': 'application/json',
      'Accept-Encoding': 'gzip, deflate, br',
      'Application-Id': regions[region],
      locale,
      countryCode: countryCode[region],
    };
 }