gboudreau / nissan-connect-php

Use the Nissan Connect (was Carwings) API using a simple PHP class.
GNU General Public License v3.0
38 stars 17 forks source link

Response Authentication error #32

Closed Raiden38 closed 4 years ago

Raiden38 commented 4 years ago

I got this message since last 2 days:

Request for 'GET https://icm.infinitiusa.com/NissanLeafProd/rest/battery/vehicles/1N4AZ1CP6XXXXXXXX/getChargingStatusRequest' failed. Response received: "<html><head><title>JBoss Web\/7.4.10.Final-redhat-1 - JBWEB000064: Error report<\/title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--><\/style> <\/head><body><h1>JBWEB000065: HTTP Status 401 - Unauthorized<\/h1><HR size=\"1\" noshade=\"noshade\"><p><b>JBWEB000309: type<\/b> JBWEB000067: Status report<\/p><p><b>JBWEB000068: message<\/b> <u>Unauthorized<\/u><\/p><p><b>JBWEB000069: description<\/b> <u>JBWEB000121: This request requires HTTP authentication.<\/u><\/p><HR size=\"1\" noshade=\"noshade\"><h3>JBoss Web\/7.4.10.Final-redhat-1<\/h3><\/body><\/html>"

Raiden38 commented 4 years ago

Anyone has the same issue? It's been down like this since May 23rd... Thx!

gboudreau commented 4 years ago

Same for me. Apparently, this code would work:

    def __init__(self, base_url, username, password):
        super(Nissan, self).__init__(base_url=base_url)

        self.api_key = self.login(username, password)
        self.account_id = self.api_key['account_id']
        conversationId = str(uuid.uuid1())
        print(self.api_key['access_token'])
        self.session.headers['CV-ConversationId'] = conversationId
        self.session.headers['Authorization'] = "Bearer " + self.api_key['access_token']
        self.session.headers['CV-ApiKey'] = self.api_key['CVApiKey']
        self.session.headers['CV-AppType'] = "MOBILE"

    def login(self, username, password):
        loginuser = 'NISNNAVCS/' + username
        r = requests.post('https://mobile.telematics.net/login/token', headers={'CV-APPID': 'cv.nissan.connect.us.android.25'}, json={'username': loginuser, 'password': password})
        print(r.json())
        return r.json()

I'll try to implement this in the new-api branch later today or tomorrow.

gboudreau commented 4 years ago

Doesn't seem to work for me. I get a 500 error. I tried using curl on the command-line too, same error.

Using this python script:

import requests

def main():
    username = "..."
    password = "..."
    loginuser = 'NISNNAVCS/' + username
    r = requests.post('https://mobile.telematics.net/login/token', headers={'CV-APPID': 'cv.nissan.connect.us.android.25'}, json={'username': loginuser, 'password': password})
    print(r.json())

if __name__ == "__main__":
    main()

I get:

{u'error_description': u'Bad Request', u'error': u'invalid_request'}

You can try the above commit, to play with it, see if you can make it work. Or if you can find any other similar project that fixed this issue, please just link to it here, and I'll take a look.

gboudreau commented 4 years ago

I was able to make it work. Problem was pretty stupid: server was returning multiple cookies, and code expected (looked for) just one... So new-api branch should be working for everyone again now. Let me know.

(Of note: that branch should work in North America; not sure if it works for 2019+ LEAF; let me know if you have one of those, and it works, or not.)

gboudreau commented 4 years ago

Oh, and you might need to delete local cache file to fix the issue; enable DEBUG to see where that file is, and just delete it.

Raiden38 commented 4 years ago

Merci 100000 fois!!! Je trouvais tellement ça poche d'utiliser l'app Nissan au lieu de mon outil! :)