nricklin/leafpy

Can't log in

Closed this issue · 15 comments

Trying to log in using my username and password (just recently reset to make sure) and all I'm getting is:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/leafpy/leaf.py", line 17, in __init__
    self.custom_sessionid, self.VIN = login(username, password, self.region_code)
  File "/usr/local/lib/python3.7/site-packages/leafpy/auth.py", line 30, in login
    raise Exception('Cannot login.  Probably username & password are wrong. ' + r.text)
Exception: Cannot login.  Probably username & password are wrong. {"status":"-2010","message":"INVALID PARAMS"}

I'm using Python 3.7.0 on OSX and entering the username and password in plain text as a test

Same error, was working until a week a go

i got it working, i downgraded it to version 0.2.2 and changed the base url to the one used in the latest version, it worked at first try.

to downgrade:
pip install leafpy==0.2.2

and change from api_v180117_NE to api_v181217_NE inside the base url.

No luck

Python 3.7.4 (new error):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/leafpy/leaf.py", line 14, in __init__
    self.custom_sessionid, self.VIN = login(username, password)
  File "/usr/local/lib/python3.7/site-packages/leafpy/auth.py", line 12, in login
    c1  = Blowfish.new(baseprm, Blowfish.MODE_ECB)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Cipher/Blowfish.py", line 146, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Cipher/__init__.py", line 79, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Cipher/_mode_ecb.py", line 215, in _create_ecb_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/usr/local/lib/python3.7/site-packages/Crypto/Cipher/Blowfish.py", line 77, in _create_base_cipher
    result = start_operation(c_uint8_ptr(key),
  File "/usr/local/lib/python3.7/site-packages/Crypto/Util/_raw_api.py", line 235, in c_uint8_ptr
    raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code

Python 2.7.16 (same error):

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/site-packages/leafpy/leaf.py", line 14, in __init__
    self.custom_sessionid, self.VIN = login(username, password)
  File "/usr/local/lib/python2.7/site-packages/leafpy/auth.py", line 30, in login
    raise Exception('Cannot login.  Probably username & password are wrong. ' + r.text)
Exception: Cannot login.  Probably username & password are wrong. {"status":"-2010","message":"INVALID PARAMS"}

I updated leaf.py and auth.py in both installations

I am certain of the username and password. I can log in at Nissan.co.uk but I can't log in to any apps for some reason including the official app. My password was recently reset and includes a numbers, capitals and a special character (which worries me - I know *NIX systems aren't super-happy with special characters in passwords historically)

Mine is working when its installed local at home-folder, but when im running it from a globally install it gives the -2010 error.
so, same setup, just running from $home/.local/lib/ works, while running from /usr/local/lib it gives -2010 error

You guys think it's related to #23 ? Or something changed serverside?

I don't think so. The error I'm getting seems to suggest that it's trying to pass a string to something that doesn't support strings if I'm reading it correctly:

TypeError: Object type <class 'str'> cannot be passed to C code

Ok - good news and bad news.

  1. I realised that I was using my Nissan account details, not my You+Nissan details
  2. I still can't log in with the current version (still the same error!)

I tried both the current version and the 0.2.2 with updated url that @Haaland87 suggested

Seems like Nissan changed the API a couple of days ago, so now its not working for me ether.

Indeed - I get a new error now using the latest version:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/phil/.local/lib/python3.7/site-packages/leafpy/leaf.py", line 17, in __init__
    self.custom_sessionid, self.VIN = login(username, password, self.region_code)
  File "/home/phil/.local/lib/python3.7/site-packages/leafpy/auth.py", line 28, in login
    r.raise_for_status()
  File "/usr/lib/python3/dist-packages/requests/models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://gdcportalgw.its-mo.com/api_v181217_NE/gdc/UserLoginRequest.php

Looks like someone's figured out the new API

https://gitlab.com/tobiaswkjeldsen/dartcarwings/issues/15

EDIT: Tried updating the BASE_URL in both auth.py and leaf.py to the value, above (https://gdcportalgw.its-mo.com/api_v190426_NE/gdc) and I'm back to the invalid username and password prompt so that seems to be the right URL

Am I doing something stupid here? How do I specify which region I'm logging in to? I'm a UK user so I think I should be using the NE region but leaf.py and auth.py both seem to set region to NNA by default. When I try to add a region either using positional or named params, it throws the INVALID PARAMS error

Thanks @pnlrogue1 ! I updated to the new url with #46 at version 0.2.6.

@pnlrogue1 I wonder if the issue is related to the switch from pycrypto to pcryptodome in 0.2.4 ?

Haven't had a go at this for a while so thought I'd try again.

Setup:

  1. Mac OSX 10.14.6
  2. Python 3.7.4
  3. Brand new virtual environment built from Python 3.7.4
  4. Installed gnureadline (helps fix some stupid problems with OSX's Python) and leafpy. Nothing else installed in the virtual environment.
Python 3.7.4 (default, Jul  9 2019, 18:13:23)
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from leafpy import Leaf
>>> leaf = Leaf('pnlrogue1','************')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/lanep/Git/Personal/GetMyLeafStatus/leafpyvenv/lib/python3.7/site-packages/leafpy/leaf.py", line 17, in __init__
    self.custom_sessionid, self.VIN = login(username, password, self.region_code)
  File "/Users/lanep/Git/Personal/GetMyLeafStatus/leafpyvenv/lib/python3.7/site-packages/leafpy/auth.py", line 30, in login
    raise Exception('Cannot login.  Probably username & password are wrong. ' + r.text)
Exception: Cannot login.  Probably username & password are wrong. {"status":"-2010","message":"INVALID PARAMS","resultKey":""}

No idea if this is related to pycryptodome but I note that it installed fine when I installed leafpy:

Installing collected packages: idna, urllib3, certifi, chardet, requests, pycryptodome, leafpy
Successfully installed certifi-2019.9.11 chardet-3.0.4 idna-2.8 leafpy-0.2.6 pycryptodome-3.9.0 requests-2.22.0 urllib3-1.25.6

I still feel like this could be my region - does this definitely work with UK/EU Leafs? I've never seen anything about how to specify a region in the documentation but I thought I found something about it when I dug into the code and it didn't look like I could specify the region at runtime

@pnlrogue1 no guarantee that it would work in your region... the URL may even be different.

You can try setting a different region at runtime like this:

leaf = Leaf(username='user', password='pass', region_code='<your_region_code>')
# the default region_code is 'NNA'

However I don't know if different region codes work with different URLs.

Haven't touched this for ages but just tried it and I was able to log in using the above setup (with NE as my region) and get data from my car:

>>> leaf = Leaf(username = 'pnlrogue1', password = 'XXXXXXXXXXXX', region_code = 'NE')
>>> leaf.BatteryStatusRecordsRequest()
{'status': 200, 'BatteryStatusRecords': []}
>>> response = leaf.BatteryStatusCheckRequest()
>> leaf.BatteryStatusCheckResultRequest(resultKey=response['resultKey'])
{'status': 200, 'responseFlag': '0'}
>>> leaf.BatteryStatusCheckResultRequest(resultKey=response['resultKey'])
{'status': 200, 'responseFlag': '1', 'operationResult': 'START', 'timeStamp': '2020-08-28 13:12:52', 'cruisingRangeAcOn': '39760.0', 'cruisingRangeAcOff': '40896.0', 'currentChargeLevel': '0', 'chargeMode': 'NOT_CHARGING', 'pluginState': 'NOT_CONNECTED', 'charging': 'NO', 'chargeStatus': 'CT', 'batteryDegradation': '4', 'batteryCapacity': '11', 'timeRequiredToFull': {'hours': '14', 'minutes': '30'}, 'timeRequiredToFull200': {'hours': '5', 'minutes': '0'}, 'timeRequiredToFull200_6kW': {'hours': '', 'minutes': ''}}