Code Monkey home page Code Monkey logo

connected-car-python-sdk's Introduction

  • ๐Ÿ‘‹ Hi, Iโ€™m @ianjwhite99
  • ๐Ÿ‘€ Iโ€™m interested in Machine Learning, Full-stack Web/Mobile App Development
  • โ˜• Interesting in supporting me or my projects? You can buy me a coffee!
  • ๐Ÿ“ซ How to reach me: [email protected]

connected-car-python-sdk's People

Contributors

agentscreech avatar alespouzar avatar clivejl avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

connected-car-python-sdk's Issues

401 - Authorization Issue

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.

connectedcar.exceptions.SyncException: Unexpected error

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?

Authentication changed?

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.

Authentication quit working

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):

  • 20.04.4 LTS (Focal Fossa)
  • Python 3.8.10
  • python3 -m pip install --upgrade connectedcar
    Requirement already up-to-date: connectedcar in ./.local/lib/python3.8/site-packages (1.3.5)
    Requirement already satisfied, skipping upgrade: requests in /usr/lib/python3/dist-packages (from connectedcar) (2.22.0)

Problem obtaining an Access Token for AU Client

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:

  • OS: Debian
  • Python 3.9.2

502 Gateway error

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

pic 1 -error
pic 2 - code

Max retries exceeded HTTPSConnectionPool

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
`

connectedcar.exceptions.ValidationException: Unknown error

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())

vehicle.capability() returning error

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.

Error 429 'Too Many Requests'

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?

Ford Account Lockout

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?

Exception: Unable to login, missing location redirect

Describe the bug
get_user_access_token fails with error: Exception: Unable to login, missing location redirect (European car!)

To Reproduce

  1. Run client = connectedcar.AuthClient('9fb503e0-715b-47e8-adfd-ad4b7770f73b', None, None) .
    Also tested client = connectedcar.AuthClient('9fb503e0-715b-47e8-adfd-ad4b7770f73b', None, None, None, 'EU') with same error
  2. Run access = client.get_user_access_token(userid, pwd)

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):

  • OS: Synology DSM 7.1-42661 Update 3
  • Script running with Python 3.8.12

Any idea?

Pascal

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.