ianjwhite99 / connected-car-python-sdk Goto Github PK
View Code? Open in Web Editor NEWOpen-source Python SDK for Ford vehicles connected with Sync Connect (Ford Pass)
License: MIT License
Open-source Python SDK for Ford vehicles connected with Sync Connect (Ford Pass)
License: MIT License
Ford changed the FordPass authentication endpoint. The Ford authorization endpoint will now only generate proper access tokens using the OAuth 2.0 Authorization Code Grant.
Python script throws a 502 Gateway error upon reaching any line that's using the access key (pic 1). I tried using every possible combination of the refreshToken and access variable with refresh_token or access_token in dict, but nothing worked. I even tried some client-side fixes like flushing DNS, but nothing. Here's the code (pic 2)
In this example the code is working fine until reaching the "vehicles" variable.
In theory it could be that the Ford changed their api endpoint, but that's unsure. Yesterday the code was working fine but today.
Note : even the file in examples folder in this repo doesn't work, same error
Some idea, what was changed ? EU region. 9.10. 2023 12:00 exactly last connection with success.
`
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='usapi.cv.ford.com', port=443): Max retries exceeded with url: /api/users/vehicles/WF0KXX.../detail?lrdt=01-01-1970%2000:00:00 (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f1ca8f209a0>: Failed to establish a new connection: [Errno -2] Name or service not known'))
import connectedcar
client = connectedcar.AuthClient(
'9fb503e0-715b-47e8-adfd-ad4b7770f73b',
None,
None) # Create client connection
access = client.get_user_access_token(
'[email protected]', 'password') # Fetch client access token
user = connectedcar.User(access['access_token']) # New User Object
vehicles = user.vehicles() # Fetch list of user vehicles
for userVehicle in vehicles: # For each user vehicle
vehicle = connectedcar.Vehicle(
userVehicle['VIN'], access['access_token']) # Create vehicle object
print(vehicle.details()) # Print vehicle details in json format
`
Describe the bug
I don't appear to be getting a sufficient response as part of the .get_user_access_token() call.
Traceback (most recent call last):
File "/sandpit/ford/test.py", line 4, in <module>
access = client.get_user_access_token('<myusername>', '<mypw>') # Fetch client access token
File "/sandpit/ford/venv/lib/python3.9/site-packages/connectedcar/connectedcar.py", line 65, in get_user_access_token
authURL = self.web_session(pkce_code)
File "/sandpit/ford/venv/lib/python3.9/site-packages/connectedcar/connectedcar.py", line 120, in web_session
authURL = re.findall('data-ibm-login-url="(.*)"\s', response.text)[0]
IndexError: list index out of range
I have also looked at what I'm getting in response.text and it appears to be a "problem" webpage... I suspect this is may be due to the fact that I'm in Australia. I've also confirmed both on the Ford Australia website and on the FordPass iOS app that my account isn't locked or anything like that.
To Reproduce - This is the script.
import connectedcar
client = connectedcar.AuthClient('9fb503e0-715b-47e8-adfd-ad4b7770f73b', None, None, None, 'AU')
access = client.get_user_access_token('<myusername>', '<mypw>') # Fetch client access token
user = connectedcar.User(access['access_token'], 'AU') # New User Object
vehicles = user.vehicles() # Fetch list of user vehicles
for userVehicle in vehicles: # For each user vehicle
vehicle = connectedcar.Vehicle(
userVehicle['vin'], access['access_token']) # Create vehicle object
print(vehicle.details()) # Print vehicle details in json format
Expected behavior
Successfully get an access token!
Desktop:
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())
Add charging endpoint.
Describe the bug
When trying to get an access token, an exception is thrown.
File "/.../.local/lib/python3.10/site-packages/connectedcar/connectedcar.py", line 105, in get_user_access_token
response = self.session.post('https://api.mps.ford.com/api/token/v2/cat-with-ci-access-token', headers=headers, data=json.dumps(data)).json()
File "/usr/lib/python3/dist-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
To Reproduce
Call client.get_user_access_token() with valid credentials.
Expected behavior
An access token.
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(
'[email protected]', '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?
Hi all,
It seems Ford has started cracking down on third party services taking advantage of their apis.
Recently I was locked out of my account and after speaking to Ford support they told me it was because of an unauthorized third party service using my credentials, which would be connected-car SDK's.
I am curious if anyone else has experienced this issue?
Describe the bug
get_user_access_token fails with error: Exception: Unable to login, missing location redirect (European car!)
To Reproduce
Expected behavior
Authentication and token were working OK prior to July 19th 2022. Last successful access on July 19th 2022 at 09:24AM
Desktop (please complete the following information):
Any idea?
Pascal
I had a script that worked regularly until about 2 weeks ago, and is now failing when trying to get the access token:
File "/.local/lib/python3.8/site-packages/connectedcar/connectedcar.py", line 63, in get_user_access_token
response = requester.call(
File "/.local/lib/python3.8/site-packages/connectedcar/requester.py", line 47, in call
raise e
File "/.local/lib/python3.8/site-packages/connectedcar/requester.py", line 29, in call
raise E.ValidationException(response)
connectedcar.exceptions.ValidationException: CSIAQ0172E The grant type [password] is not supported. Supported grant types are [authorization_code, refresh_token].
To Reproduce
` odo['odometer'] = odo.pop('data');
"/data/[email protected]/personal/ranger.py" 32L, 1039C 1,1 Top
#!/usr/bin/python3
import connectedcar
import json
client = connectedcar.AuthClient(
'9fb503e0-715b-47e8-adfd-ad4b7770f73b',
None,
None) # Create client connection
access = client.get_user_access_token(
'', '') # Fetch client access token
user = connectedcar.User(access['access_token']) # New User Object
vehicles = user.vehicles() # Fetch list of user vehicles
`
Expected behavior
I expected to get an access token and list of vehicles.
Desktop (please complete the following information):
Describe the bug
Looks like there are to many Requests with this Application ID.
Fetch Auth Token doesn't work anymore.
Function call, requester.py:49 get_user_access_token, connectedcar.py:75
Response 429
To Reproduce
Run Example
Additional context
Changed IP-Adress and created a new User, so think its the Application ID.
Do you have the same problem?
Originally posted by plamish January 5, 2022
Hey @ianjwhite99, great and neat work. Thanks for the SDK.
Here is URL for checking active recalls you may consider adding as new functionality:
https://api.mps.ford.com/api/recall/v1/recalls?vin=&language=DE®ion=CH&country=CHE
Cheers
When calling currentVehicle.capability(), I get a python traceback. I suspect ford discontinued the URI that was providing capability information. What info did it used to have?
To Reproduce
print( currentVehicle.capability() )
Traceback (most recent call last):
File "/home/bcroan/.local/lib/python3.6/site-packages/connectedcar/requester.py", line 35, in call
raise E.ResourceNotFoundException(response)
File "/home/bcroan/.local/lib/python3.6/site-packages/connectedcar/exceptions.py", line 9, in init
json = response.json()
File "/usr/lib/python3.6/site-packages/requests/models.py", line 897, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib64/python3.6/json/init.py", line 354, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python3.6/json/decoder.py", line 342, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/bcroan/bin/LogFusionData.py", line 30, in
print( currentVehicle.capability() )
File "/home/bcroan/.local/lib/python3.6/site-packages/connectedcar/vehicle.py", line 137, in capability
const.USER_URL, 'capability/v1/vehicles/' + self.vehicle_id)
File "/home/bcroan/.local/lib/python3.6/site-packages/connectedcar/api.py", line 59, in get
return requester.call('GET', url, headers=headers)
File "/home/bcroan/.local/lib/python3.6/site-packages/connectedcar/requester.py", line 49, in call
raise E.SyncException("Unexpected error") from e
connectedcar.exceptions.SyncException: Unexpected error
Expected behavior
list capabilities of vehicle
Desktop (please complete the following information):
Fedora 36, Python 3
I an able to enumerate vin numbers on the account and door lock status, so authentication is working properly.
Is there any plans to enable for India region?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.