bimmerconnected / bimmer_connected

🚘 Library to query the status of your BMW or Mini from the ConnectedDrive portal
Apache License 2.0
362 stars 79 forks source link

KeyError: 'access_token' #177

Closed pmiola73 closed 4 years ago

pmiola73 commented 4 years ago

Describe the issue Hi all I have installed bimmer connected and I get this error:

DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:getting new oauth token DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): customer.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://customer.bmwgroup.com:443 "POST /gcdm/oauth/authenticate HTTP/1.1" 302 None Traceback (most recent call last): File "/usr/bin/bimmerconnected", line 10, in sys.exit(main()) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 82, in main args.func(args) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 112, in fingerprint account = ConnectedDriveAccount(args.username, args.password, get_region_from_name(args.region), File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 61, in init self._get_vehicles() File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 226, in _get_vehicles self._get_oauth_token() File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 126, in _get_oauth_token self._oauth_token = response_json['access_token'] KeyError: 'access_token'

Expected behavior see the services in Home Assistant

Home Assistant version arch: armv7 image: homeassistant/raspberrypi3-homeassistant last_version: 0.108.8 machine: raspberrypi3 version: 0.108.8

Your config.yaml

bmw_connected_drive:
  name:
    username: "username"
    password: "password"
    region: "rest_of_world"

Output of bimmer_connected fingerprint If you have run the bimmer_connected fingerprint please share that data here

DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:getting new oauth token DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): customer.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://customer.bmwgroup.com:443 "POST /gcdm/oauth/authenticate HTTP/1.1" 302 None Traceback (most recent call last): File "/usr/bin/bimmerconnected", line 10, in sys.exit(main()) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 82, in main File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 112, in fingerprint account = ConnectedDriveAccount(args.username, args.password, get_region_from_name(args.region), File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 61, in init self._get_vehicles() File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 226, in _get_vehicles self._get_oauth_token() File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 126, in _get_oauth_token self._oauth_token = response_json['access_token'] KeyError: 'access_token' Screenshot 2020-04-23 at 19 01 21

rikroe commented 4 years ago

Please install the debug branch I just have uploaded, try again and post the console output:

pip3 install -e git+https://github.com/bimmerconnected/bimmer_connected.git@debug#egg=bimmer_connected 

⚠️⚠️⚠️⚠️⚠️⚠️ BEWARE!! This output most probably will include non-sanitized data for your account such as access_token or car data. Please be careful to remove this before posting here (or wait at least two hours for the tokens to become invalid)!

gerard33 commented 4 years ago

@pmiola73 Please try rikroes response in #61 first ->

Is there any difference when you enter username and password in quotes or without? I can reproduce this issue when username or password are incorrect. Please check again!

pmiola73 commented 4 years ago

After installing:

pip3 install -e git+https://github.com/bimmerconnected/bimmer_connected.git@debug#egg=bimmer_connected

this is the output of this command:

bimmerconnected fingerprint username password rest_of_world

OUTPUT

DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:getting new oauth token DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): customer.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://customer.bmwgroup.com:443 "POST /gcdm/oauth/authenticate HTTP/1.1" 302 None DEBUG:bimmer_connected.account:Parsing https://www.bmw-connecteddrive.com/app/static/external-dispatch.html#access_token=TOKEN&token_type=Bearer&expires_in=7199 to {"access_token": "TOKEN", "token_type": "Bearer", "expires_in": "7199"} DEBUG:bimmer_connected.account:got new token TOKEN with expiration date 2020-04-24 19:18:28.242573 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.com:443 "GET /webapi/v1/user/vehicles HTTP/1.1" 200 None DEBUG:bimmer_connected.account:Vehicles: {"vehicles":[{"vin":"VIN","model":"X5 xDrive25d","bodytype":"F15","driveTrain":"CONV","fuelType":"DIESEL","color":"CARBONSCHWARZ METALLIC","colorCode":"416","brand":"BMW","yearOfConstruction":2017,"statisticsCommunityEnabled":false,"statisticsAvailable":false,"hub":"HUB_ECE","hasAlarmSystem":false,"dealer":{"name":"BIAUTO SRL","street":"VIA BOLOGNA, 102","postalCode":"10154","city":"TORINO","country":"IT","phone":"+39 011 19214666"},"breakdownNumber":"+4989358957103","countryCode":"V1-IT","steering":"LH","vehicleFinderRestriction":"NONE","hmiVersion":"ID5","a4a":"USB_ONLY","vehicleFinder":"NOT_SUPPORTED","remote360":"NOT_SUPPORTED","hornBlow":"NOT_SUPPORTED","lightFlash":"NOT_SUPPORTED","doorLock":"NOT_SUPPORTED","doorUnlock":"NOT_SUPPORTED","climateControl":"NOT_SUPPORTED","climateNow":"NOT_SUPPORTED","climateNowRES":"NOT_SUPPORTED","climateControlRES":"NOT_SUPPORTED","chargingControl":"NOT_SUPPORTED","chargeNow":"NOT_SUPPORTED","sendPoi":"ACTIVATED","rangeMap":"NOT_SUPPORTED","lastDestinations":"NOT_SUPPORTED","intermodalRouting":"NOT_AVAILABLE","climateFunction":"VENTILATION","onlineSearchMode":"MAP","smartSolution":"NOT_SUPPORTED","carCloud":"ACTIVATED","lscType":"NOT_SUPPORTED","ipa":"NOT_SUPPORTED","puStep":"0319","exFactoryPUStep":null,"remoteSoftwareUpgrade":"NOT_SUPPORTED"}]} DEBUG:bimmer_connected.state:requesting new data from connected drive DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.com:443 "GET /webapi/v1/user/vehicles/VIN/status?deviceTime=2020-04-24T17%3A18%3A30&dlat=0.0&dlon=0.0 HTTP/1.1" 404 None DEBUG:bimmer_connected.account:The BMW Connected Drive portal returned an error: NOT_FOUND (received status code 404 and expected 200). DEBUG:bimmer_connected.account:{"error":{"code":500,"description":"(SmartPhoneUtil-A-2012) Ressource not found. No status available for VIN"}} Traceback (most recent call last): File "/usr/bin/bimmerconnected", line 10, in sys.exit(main()) File "/bin/src/bimmer-connected/bimmer_connected/cli.py", line 226, in main args.func(args) File "/bin/src/bimmer-connected/bimmer_connected/cli.py", line 119, in fingerprint account.update_vehicle_states() File "/bin/src/bimmer-connected/bimmer_connected/account.py", line 259, in update_vehicle_states car.update_state() File "/bin/src/bimmer-connected/bimmer_connected/vehicle.py", line 72, in update_state self.state.update_data() File "/bin/src/bimmer-connected/bimmer_connected/state.py", line 128, in update_data response = self._account.send_request( File "/bin/src/bimmer-connected/bimmer_connected/account.py", line 178, in send_request raise IOError(msg) OSError: The BMW Connected Drive portal returned an error: NOT_FOUND (received status code 404 and expected 200).

Edit by rikroe: removed VIN and token

rikroe commented 4 years ago

Ok, this is even more weird. This time you get the access_token but the API has no status for your car... I'm a little a a loss here...

My guess is that that are hickups @ BMW server so maybe just keep wait a couple of days if that is possible?

Alternatively, you could try our beta for adjusted (new) BMW servers:

pip3 install bimmer_connected==0.8.0.0b1

(or replace 0.8.0.0.b1 with 0.7.5 to go back to the version shipped with HA).

pmiola73 commented 4 years ago

just installed version 0.8.0.0b1 but I get the same issue

DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:getting new oauth token DEBUG:bimmer_connected.account:getting new GCDM token DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): customer.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://customer.bmwgroup.com:443 "POST /gcdm/oauth/token HTTP/1.1" 200 None DEBUG:bimmer_connected.account:got new GCDM token TOKEN DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myc-profile.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://myc-profile.bmwgroup.com:443 "GET /api/Account/ExternalLogin?provider=GCDM&response_type=token&redirect_uri=https%3A%2F%2Fmyc-profile.bmwgroup.com%2F&client_id=self HTTP/1.1" 302 0 DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://api.bmwgroup.com:443 "GET /gcdm/protected/%7BclientId%7D/%7BclientVariantId%7D/customers/userAccount?response_type=code&client_id=d766b537-a654-4cbd-a3dc-0ca5672d7f8d&redirect_uri=https%3A%2F%2Fmyc-profile.bmwgroup.com%2Foauth_callback.html&scope=authenticate_user&state=ZQu5Ba66TJxwAa1aVKKgRQCwyZREo8IumYu_aL1aRqIcu5GslR9bBQKrMyeumbZBbu9uvlgOpElxV1FfWWdAjtC7ALOuvPQoQovZd695rPaT-iKSzAk02NpK5fMcuIUAutAcQkoqJQzcB2c06qxjy86-L7uwop-SQ6KgYlnFFzhoWt-vn-1qmr6Fbg_8OJtvdQFFKB4wYzrKqptw9bJ5IrznPT_6efwQQImegu4Ysg1N4vW5xz0DD85I8uDSFZkM79w_YuA8nz8Wg6E4d4gj2CEGHZ3S5g9r3wfH7Oof5CQuZKPXhA6ButtemD7Zg3gdJNtwlg6KMBXsUsq33kcSI95cq12rorWIER7B3GxKhOARu2MD7RboEGpGKOxo4gaNfft4GlZjqZg7feLu9tqHUA HTTP/1.1" 404 None DEBUG:urllib3.connectionpool:https://myc-profile.bmwgroup.com:443 "GET /oauth_callback.html?scope=authenticate_user&refresh=lRqPV9u7krjNpH1PN5cTNh7eUYBDwuMtn3yU9IludJeINmND&state=ZQu5Ba66TJxwAa1aVKKgRQCwyZREo8IumYu_aL1aRqIcu5GslR9bBQKrMyeumbZBbu9uvlgOpElxV1FfWWdAjtC7ALOuvPQoQovZd695rPaT-iKSzAk02NpK5fMcuIUAutAcQkoqJQzcB2c06qxjy86-L7uwop-SQ6KgYlnFFzhoWt-vn-1qmr6Fbg_8OJtvdQFFKB4wYzrKqptw9bJ5IrznPT_6efwQQImegu4Ysg1N4vW5xz0DD85I8uDSFZkM79w_YuA8nz8Wg6E4d4gj2CEGHZ3S5g9r3wfH7Oof5CQuZKPXhA6ButtemD7Zg3gdJNtwlg6KMBXsUsq33kcSI95cq12rorWIER7B3GxKhOARu2MD7RboEGpGKOxo4gaNfft4GlZjqZg7feLu9tqHUA&token=TOKEN HTTP/1.1" 302 0 DEBUG:urllib3.connectionpool:https://myc-profile.bmwgroup.com:443 "GET /api/Account/ExternalLogin?provider=GCDM&response_type=token&redirect_uri=https%3A%2F%2Fmyc-profile.bmwgroup.com%2F&client_id=self HTTP/1.1" 302 0 DEBUG:urllib3.connectionpool:https://myc-profile.bmwgroup.com:443 "GET / HTTP/1.1" 200 0 DEBUG:bimmer_connected.account:got new token TOKEN with expiration date 2020-04-24 18:56:09.678396 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myc-profile.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://myc-profile.bmwgroup.com:443 "GET /api/gateway/brs/webapi/v1/user/vehicles HTTP/1.1" 200 None DEBUG:bimmer_connected.state:requesting new data from connected drive DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): myc-profile.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://myc-profile.bmwgroup.com:443 "GET /api/gateway/brs/webapi/v1/user/vehicles/VIN/status?deviceTime=2020-04-24T17%3A58%3A10&dlat=0.0&dlon=0.0 HTTP/1.1" 404 18 DEBUG:bimmer_connected.account:The BMW Connected Drive portal returned an error: NOT_FOUND (received status code 404 and expected 200). DEBUG:bimmer_connected.account:Resource not found Traceback (most recent call last): File "/usr/bin/bimmerconnected", line 10, in sys.exit(main()) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 226, in main args.func(args) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 119, in fingerprint account.update_vehicle_states() File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 289, in update_vehicle_states car.update_state() File "/usr/lib/python3.8/site-packages/bimmer_connected/vehicle.py", line 72, in update_state self.state.update_data() File "/usr/lib/python3.8/site-packages/bimmer_connected/state.py", line 128, in update_data response = self._account.send_request( File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 208, in send_request raise IOError(msg) OSError: The BMW Connected Drive portal returned an error: NOT_FOUND (received status code 404 and expected 200).

pmiola73 commented 4 years ago

and this is the output after installing 0.7.5

bimmer_connected $ pip3 install bimmer_connected==0.7.5 Collecting bimmer_connected==0.7.5 Downloading https://files.pythonhosted.org/packages/1c/1a/19f6f3134d66978ec686b234e525467d0b8441c8d14b3edd9cfe7c908c10/bimmer_connected-0.7.5-py3-none-any.whl Requirement already satisfied: requests in /usr/lib/python3.8/site-packages (from bimmer_connected==0.7.5) (2.23.0) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/lib/python3.8/site-packages (from requests->bimmer_connected==0.7.5) (1.25.9) Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python3.8/site-packages (from requests->bimmer_connected==0.7.5) (2020.4.5.1) Requirement already satisfied: chardet<4,>=3.0.2 in /usr/lib/python3.8/site-packages (from requests->bimmer_connected==0.7.5) (3.0.4) Requirement already satisfied: idna<3,>=2.5 in /usr/lib/python3.8/site-packages (from requests->bimmer_connected==0.7.5) (2.9) Installing collected packages: bimmer-connected Found existing installation: bimmer-connected 0.8.0.0b1 Uninstalling bimmer-connected-0.8.0.0b1: Successfully uninstalled bimmer-connected-0.8.0.0b1 Successfully installed bimmer-connected-0.7.5 WARNING: You are using pip version 19.2.3, however version 20.0.2 is available. You should consider upgrading via the 'pip install --upgrade pip' command. bimmer_connected $ bimmerconnected fingerprint pmiola@gmail.com chepall3 rest_of_world DEBUG:bimmer_connected.account:Getting vehicle list DEBUG:bimmer_connected.account:getting new oauth token DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): customer.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://customer.bmwgroup.com:443 "POST /gcdm/oauth/authenticate HTTP/1.1" 302 None DEBUG:bimmer_connected.account:got new token TOKEN with expiration date 2020-04-24 19:59:19.252916 DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.com:443 "GET /webapi/v1/user/vehicles HTTP/1.1" 200 None DEBUG:bimmer_connected.state:requesting new data from connected drive DEBUG:bimmer_connected.account:Old token is still valid. Not getting a new one. DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): b2vapi.bmwgroup.com:443 DEBUG:urllib3.connectionpool:https://b2vapi.bmwgroup.com:443 "GET /webapi/v1/user/vehicles/VIN/status?deviceTime=2020-04-24T17%3A59%3A21&dlat=0.0&dlon=0.0 HTTP/1.1" 404 None DEBUG:bimmer_connected.account:The BMW Connected Drive portal returned an error: NOT_FOUND (received status code 404 and expected 200). DEBUG:bimmer_connected.account:{"error":{"code":500,"description":"(SmartPhoneUtil-A-2012) Ressource not found. No status available for VIN VIN"}} Traceback (most recent call last): File "/usr/bin/bimmerconnected", line 10, in sys.exit(main()) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 82, in main args.func(args) File "/usr/lib/python3.8/site-packages/bimmer_connected/cli.py", line 118, in fingerprint account.update_vehicle_states() File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 251, in update_vehicle_states car.update_state() File "/usr/lib/python3.8/site-packages/bimmer_connected/vehicle.py", line 72, in update_state self.state.update_data() File "/usr/lib/python3.8/site-packages/bimmer_connected/state.py", line 128, in update_data response = self._account.send_request( File "/usr/lib/python3.8/site-packages/bimmer_connected/account.py", line 170, in send_request raise IOError(msg) OSError: The BMW Connected Drive portal returned an error: NOT_FOUND (received status code 404 and expected 200). bimmer_connected $

rikroe commented 4 years ago

Mhh. Then I have no idea why it doesn't work. Maybe one thing you could try to add lat and lon coords to the fingerprint:

bimmerconnected fingerprint [-h]
                                   username password
                                   {north_america,china,rest_of_world} [lat]
                                   [lng]
rikroe commented 4 years ago

If that still does not work for you, could you please contact me at rikro at gmx dot net?

Btw: Do you see the status of your car in the Connected App?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.