calmjm / tojota

Functions for interacting with Toyota MyT API
Apache License 2.0
74 stars 15 forks source link

Get odometer info... error #21

Open moseisleydk opened 3 years ago

moseisleydk commented 3 years ago

╰─# python ./tojota.py 2021-01-31 10:46:51,682:main:INFO: Fetching trips... 2021-01-31 10:46:52,038:main:INFO: Failed to use cached token, doing fresh login... 2021-01-31 10:46:52,038:main:INFO: Logging in... 2021-01-31 10:46:52,812:main:INFO: Fetching trips... 2021-01-31 10:46:53,384:main:INFO: Get parking info... Didn't get parking information! 2021-01-31 10:46:53,719:main:INFO: Get odometer info... Traceback (most recent call last): File "./tojota.py", line 457, in sys.exit(main()) File "./tojota.py", line 399, in main odometer, odometer_unit, fuel_percent, fresh = myt.get_odometer_fuel() File "./tojota.py", line 232, in get_odometer_fuel raise ValueError('Failed to get data {} {} {}'.format(r.text, r.status_code, r.headers)) ValueError: Failed to get data 204 {'Cache-Control': 'no-cache, no-store, max-age=0, must-revalidate', 'Pragma': 'no-cache', 'Expires': '0', 'Server': 'Jetty(9.3.25.v20180904)', 'Request-Context': 'appId=**', 'ID': '****, 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block', 'X-Frame-Options': 'DENY', 'X-Powered-By': 'ASP.NET', 'Set-Cookie': 'ARRAffinity=*;Path=/;HttpOnly;Secure;Domain=myt-agg.toyota-europe.com, ARRAffinitySameSite=**;Path=/;HttpOnly;SameSite=None;Secure;Domain=myt-agg.toyota-europe.com, visid_incap_2173333=**; expires=Sun, 30 Jan 2022 11:49:57 GMT; HttpOnly; path=/; Domain=.toyota-europe.com, incapses*****==; path=/; Domain=.toyota-europe.com, utmvmoZBuyvPZZ=EKlDNdcLjba; path=/; Max-Age=900, utmvaoZBuyvPZZ=ARX\x01PDSQ; path=/; Max-Age=900, ___utmvboZBuyvPZZ=CZZ\r\n XKkOUalY: XtT; path=/; Max-Age=900', 'Date': 'Sun, 31 Jan 2021 09:46:53 GMT', 'X-CDN': 'Incapsula', 'X-Iinfo': '2-**** PNNy RT(1612086413591 21) q(0 0 0 0) r(2 2) U11'} (tojota) ╭─root@sparrow ~/tojota ‹master*› ╰─#

moseisleydk commented 3 years ago

Thanks for fixing #16

moseisleydk commented 3 years ago

ok, MyT app stalls at 65% now .... will test later

moseisleydk commented 3 years ago

Ok, MyT works now:

IMG_8454

calmjm commented 3 years ago

I suggest you check your VIN from the config. It seems that when you have invalid VIN there all the data is returned as HTTP 204 instead of expected HTTP 403. Maybe you have copy-paste error there?

moseisleydk commented 3 years ago

Hi,

You were correct, my bad :-(

Current status:

╰─# python ./tojota.py 2021-01-31 11:10:00,142:main:INFO: Fetching trips... 2021-01-31 11:10:01,543:main:INFO: Failed to use cached token, doing fresh login... 2021-01-31 11:10:01,544:main:INFO: Logging in... 2021-01-31 11:10:02,536:main:INFO: Fetching trips... Traceback (most recent call last): File "./tojota.py", line 371, in main trips, fresh = myt.get_trips() File "./tojota.py", line 161, in get_trips self._write_file(trips_file, r.text) File "./tojota.py", line 109, in _write_file f.write(contents) UnicodeEncodeError: 'ascii' codec can't encode character '\xe6' in position 170: ordinal not in range(128)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "./tojota.py", line 457, in sys.exit(main()) File "./tojota.py", line 375, in main trips, fresh = myt.get_trips() File "./tojota.py", line 161, in get_trips self._write_file(trips_file, r.text) File "./tojota.py", line 109, in _write_file f.write(contents) UnicodeEncodeError: 'ascii' codec can't encode character '\xe6' in position 170: ordinal not in range(128) (tojota) ╭─root@sparrow ~/tojota ‹master*› ╰─#

moseisleydk commented 3 years ago

Argh - think I have solved that earlier with something in the top line ...

moseisleydk commented 3 years ago

no, adding:

encoding=utf8

Did not solve it

calmjm commented 3 years ago

Which python version are you using?

moseisleydk commented 3 years ago

(tojota) ╭─root@sparrow ~/tojota ‹master› ╰─# python --version 1 ↵ Python 3.6.9 (tojota) ╭─root@sparrow ~/tojota ‹master› ╰─#

calmjm commented 3 years ago

Hmm. Python 3.x should not have that problem at all. Adding # -- coding: utf-8 -- was the fix for python 2.

moseisleydk commented 3 years ago

Anything I can do to assist? I am a total python noob

calmjm commented 3 years ago

Can you provide that problematic trips file as an attachment here? Get trips.json with curl like

curl -H 'X-TME-TOKEN: [your_secret_token]' -o trips.json https://cpb2cs.toyota-europe.com/api/user/[your_uuid]/cms/trips/v2/history/vin/[your_vin]/1

where [your_secret_token] and [your_uuid] can be found from cache/user_data.json after you have run tojota.py recently and [vin] is your car VIN.

If you don't feel comfortable posting your driving data here send it via email to me.

moseisleydk commented 3 years ago

No problem, heres there file. Im from Denmark, så some æøå

trips.zip

calmjm commented 3 years ago

I'm in Finland so we have some öäöä here too and those are not a problem. File content seems to be fine for me, need to do some more python testing with it.

moseisleydk commented 3 years ago

Sure, do leave a message for me if my tests are needed. Appreciate the effort!!

BR,

Normann