Giter Site home page Giter Site logo

python-carnet-client's Introduction

python-carnet-client

FYI. I have no time or options to develop this code further. A newer version can be found at https://github.com/bgewehr/volkswagen-carnet-client. Have fun developing this to the next level.

Python script we_connect_clinet.py emulates the VW WE Connect web site to send commands to your car and get status.

You must have a VW WE Connect (formerly CarNet) userid and password. Also make sure to logon to the portal https://www.portal.volkswagen-we.com first before using the script. The VW site prompts for several items at first logon the script does not handle.

As of version 2.6 the script supports Secure PIN based commands as well.

This script requires the requests library. To install it, run pip install requests.

Based of work from wez3 at https://github.com/wez3/volkswagen-carnet-client It has similar functions and Charging control for electric VW's

The first two parameters are your userid and password (in single quotes!), the optional third is the command.

Avaible commands to the script are: startCharge, stopCharge, getCharge, startClimat, stopClimat, getClimat, startClimate, getClimate, stopClimate, setTemperatureForClimate, startWindowMelt, stopWindowMelt, getWindowMelt, getLatestReport, getAlerts, getGeofences Commands needing a secure pin
remoteUnlock, startRemoteVentilation, stopRemoteVentilation, startRemoteHeating, stopRemoteHeating

If no command is specified the full car status is retreived.

Usage:

usage: we_connect_client.py [-h] -u USER -p PASSWORD [-v VIN]
                            [-c {startCharge,stopCharge,getCharge,startClimate,stopClimate,getClimate,setTemperatureForClimate, startWindowMelt,stopWindowMelt,getWindowMelt,getVIN,remoteLock,remoteUnlock,startRemoteVentilation,stopRemoteVentilation,startRemoteHeating,stopRemoteHeating,getRemoteHeating,getLatestReport,getAlerts,getGeofences}]
                            [-s SPIN] [-i {0,1,2,3,4,5,6,7,8,9}] [-d]

Control your Connected VW.

optional arguments:
  -h, --help            show this help message and exit
  -u USER, --user USER  Your WE-Connect user id.
  -p PASSWORD, --password PASSWORD
                        Your WE-Connect password.
  -v VIN, --vin VIN     Your car VIN if more cars on account.
  -c {startCharge,stopCharge,getCharge,startClimate,stopClimate,getClimate,setTemperatureForClimate, startWindowMelt,stopWindowMelt,getWindowMelt,getVIN,remoteLock,remoteUnlock,startRemoteVentilation,stopRemoteVentilation,startRemoteHeating,stopRemoteHeating,getRemoteHeating,getLatestReport,getAlerts,getGeofences}, --command {startCharge,stopCharge,getCharge,startClimate,stopClimate,getClimate,setTemperatureForClimate, startWindowMelt,stopWindowMelt,getWindowMelt,getVIN,remoteLock,remoteUnlock,startRemoteVentilation,stopRemoteVentilation,startRemoteHeating,stopRemoteHeating,getRemoteHeating,getLatestReport,getAlerts,getGeofences}
                        Command to send.
  -s SPIN, --spin SPIN  Your WE-Connect s-pin needed for some commands.
  -i {0,1,2,3,4,5,6,7,8,9}, --index {0,1,2,3,4,5,6,7,8,9}
                        To get the VIN for the N-th car.
  -d, --debug           Show debug commands.
  -a, --argument        Set argument for command (ex : temperature value for setTemperatureForClimate)

Command example:

python we_connect_client.py -u '<userid>' -p '<pwd>' -c startCharge

python-carnet-client's People

Contributors

bgewehr avatar birgersp avatar sh0n avatar youpixel avatar

Stargazers

 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  avatar  avatar  avatar  avatar  avatar  avatar

python-carnet-client's Issues

Featur Request: Getting battery State Of Charge (SoC) for eGolf and other EVs

Hi, on the WeConnect portal there are two information about the battery of the EV: estimated range mileage and the state of charge (SoC, usually in %).

While the range is a number and already available in your carnet client, the SoC only appears as a picture, see screenshot:
https://chrm.info/tmp/we_portal_egolf.png

The picture is an embedded svg graphics (CSS class "ct-chart-donut") which visualize the SoC in 10% chunks.

Is it possible to parse the svg data and make the SoC available?
How can I provide more info for this function?

Thank you for your good work!

Help to get it work in c++

Hi Everybody!
Sorry, that I post here, there is nothing wrong with the script.
I am converting it to work in C++ with libcurl, but i stuck in Step 5 of login procedure.
I allways get a bad request response.
Below detailed infos.
Does anyone see what went wrong?

Thanks,
Burkhard

URL:
https://identity.vwgroup.io//signin-service/v1/b7a5bb47-f875-47cf-ab83-2ba3bf6bb738@apps_vw-dilab_com/login/identifier
Postfields: email=[email protected]&relayState=9f098e5f5a20a5efc218b97f4b87667e21492b0b&hmac=bfe175979aeb2eb47c82e80a37693eca71f834dcd798f54c567f651d8549c86b&_csrf=237c3c0f-6f01-4f09-9f6a-2a3530ceb75a
Headers: (rportet by curl debug)
Host: identity.vwgroup.io
0085: Cookie: SESSION=MjdmMDM2NWQtNmMxYS00MWE2LWIxODgtZmJhMWZiMmQ4MjEw
00c5: ; vcap_journey=6ffe6716-07cf-4a33-9cfa-e18d21283b7a
00fa: Accept-Encoding: gzip, deflate, br
011e: Accept-Language: en-US,nl;q=0.7,en;q=0.3
0148: Accept: 'text/html,application/xhtml+xml,application/xml,applica
0188: tion/json;q=0.9,/;q=0.8
01a3: User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) G
01e3: ecko/20100101 Firefox/68.0
01ff: Connection: keep-alive
0217: Pragma: no-cache
0229: Cache-Control: no-cache
0242: Content-Type: application/x-www-form-urlencoded
0273: Referer: https://identity.vwgroup.io/signin-service/v1/signin/b
02b3: 7a5bb47-f875-47cf-ab83-2ba3bf6bb738@apps_vw-dilab_com?relayState
02f3: =9f098e5f5a20a5efc218b97f4b87667e21492b0b

Responseheader:
HTTP/1.1 400 Bad Request
Date: Mon, 20 Jan 2020 12:58:29 GMT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Language: en
Expires: 0
Pragma: no-cache
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-Vcap-Request-Id: 0bd75c0e-30e1-468c-5ca4-41acb93a96bf
X-Xss-Protection: 1; mode=block

Changes to Portal

Hi!
Are there any news about the changes of today "Das We Connect Portal verabschiedet sich am 27.04.2021", it looks like that broke all my scripts using this great project here - is there a way to revive it?
Regards,
Thomas

Catching exceptions inside functions?

Hi,

I noticed you're catching exceptions inside functions. Example:

def extract_csrf(string):
    # Get value from HTML head _csrf meta tag.
    try:
        csrf_re = re.compile('<meta name="_csrf" content="(.*?)"/>')
        resp = csrf_re.search(string).group(1)
    except:
        resp = ''
    return resp

Why are you doing this? Exceptions are meant to show the developers exactly where a problem occurs. When you are doing this, you're reducing the error to a single line of text which makes the developer have to dig through the source code to find the source of error.

Also now the script has to check the result of each of the functions, which is unnecessary when you have exceptions interrupting the execution of the script. As shown here:

    landing_page_response = session.get(landing_page_url)
    if landing_page_response.status_code != 200:
        return '', 'Failed getting to portal landing page.'
    csrf = extract_csrf(landing_page_response.text)
    if csrf == '':
        return '', 'Failed to get CSRF from landing page.'

The example function should simply be:

def extract_csrf(string):
    # Get value from HTML head _csrf meta tag.
    csrf_re = re.compile('<meta name="_csrf" content="(.*?)"/>')
    return csrf_re.search(string).group(1)

Issue: Unable to get past error: Failed to post portlet page.

Hi!

Does anyone know why my application stops at "Failed to post portlet page"?

I enabled debugging and this is the reply:

reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Mon, 02 Sep 2019 12:15:04 GMT
header: Server: Apache
header: X-Environment: neo-http-4
header: Strict-Transport-Security: max-age=31536000; includeSubDomains
header: X-Content-Type-Options: nosniff
header: X-Frame-Options: SAMEORIGIN
header: X-XSS-Protection: 1; mode=block
header: Expires: Thu, 01 Jan 1970 00:00:00 GMT
header: Cache-Control: private, no-cache, no-store, must-revalidate
header: Pragma: no-cache
header: Vary: Accept-Encoding,User-Agent
header: Content-Encoding: gzip
header: Content-Length: 9751
header: Content-Type: text/html;charset=UTF-8
DEBUG:requests.packages.urllib3.connectionpool:https://www.portal.volkswagen-we.com:443 "POST /portal/web/guest/complete-login?p_auth=uq2L0Xel&p_p_id=33_WAR_cored5portlet&p_p_lifecycle=1&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_33_WAR_cored5portlet_javax.portlet.action=getLoginStatus HTTP/1.1" 200 9751

Adding new maintainers to the project

Hello Rene,
would it be possible for me to get more privileges for this project? I'm interested in further improving the functionality and quality of this amazing library.
Adding more collaborators would allow for a faster development cycle and less work for you.

Login fails at step 6: "code" and "state" cannot be extraced from response

Hi,

It seems VW changed something regarding login step 5/6.

In step 6, the application fails to extract "state" and "code" from the response url.

    login_action2_url = auth_base_url + '/signin-service/v1/' + client_id + '/login/authenticate'
    login_post_response = session.post(login_action2_url, data=login_data, headers=auth_request_headers, allow_redirects=True, verify=certverify)
    if login_post_response.status_code != 200:
        return '', 'Failed to process login sequence.'
    ref2_url = login_post_response.url                      
    portlet_code = extract_url_parameter(ref2_url, 'code')
    state = extract_url_parameter(ref2_url, 'state')

In my most recent attempt, the response URL looked like this:

https://identity.vwgroup.io/signin-service/v1/consent/users/f7427f16-d0d3-4bdc-b46d-ba8bc2be9be5/b7a5bb47-f875-47cf-ab83-2ba3bf6bb738@apps_vw-dilab_com?scopes=openid%20profile%20birthdate%20nickname%20address%20email%20phone%20cars%20dealers%20mbb&relayState=028081fad32f5f9e65542f6f8c5421a0e2cd3855&callback=https://identity.vwgroup.io/oidc/v1/oauth/client/callback&hmac=a5a379dbc3eaca571a6d6c641d431d416802b20fc5180dd78edcb9385182b490

Remove "version" and "date" from script

Version and date written explicitly in the script is unnecessary. This is why you use git.

Comments about who did what in the script are also unnecessary, but less annoying since you don't have to keep updating the text as the code evolves.

I propose that the "version" and "date" lines in the script are removed.

Login not working anymore?

Hi,

I use the "vw_carnet_web.py retrieveCarNetInfo" Skript directly and process the data afterwards.
Since some days the logon seems not to work anymore. At least no data is returned anymore :(

(Why can't VW simply offer a formal data retrieval point ? :( )

WeConnect ID support?

Recent VW ID cars like ID.3 do no longer see to appear in the โ€žoldโ€œ carnet portal (or do so by chance). Further, the new WeConnect ID app provides more precise battery soc values than the old portal which had only 10% steps.

Would appreciate any feedback on details of the login/api flow for the newer weconnect id app.

Select Car

Hello Folks!

Thanks for your work so far. I am now facing the "problem" that my account has two active cars and the second one is the e-Golf which is my target.
I can't access the eManager using this script. Reason: the first car (Touran) is selectes as the acitve one in the session "garage". The request of "eManager details" does not contain the vin in it to select the eGolf.
Is there a way, to select the eGolf as the active car for the session, may be by the vin?
If not, it is no problem.
The workaorund would be, to create a new account with only the eGolf registered.

Thanks for answers,
Burkhard

Development should take place in main branch

Hi,

I see you've created another branch for development, now with two scripts doing virtually the same thing.
Why is this? If you want to keep a "stable" version of the script, create a tag on a commit where the script was working as intended.

I propose:

  • Merge "development" into master,
  • remove development,
  • remove "vw_carnet_rb1.py"
  • commit
  • tag with "v1" or something similar

External temperature

Winter is coming! A big thank you to everyone who helped fix this script - nothing like telling Siri to heat up the car on those freezing mornings.

But how freezing are they? The earlier API included external temperature, but I am not seeing an example of that in the latest version. Any pointers how I could get it?

Continue when not logged out

Hi!
While writing my C++ code, I connected to VW without logging out, because the code was not ready.
If I had proceed to the end of step7, login has completed and stay this way, even over night.
When starting my code again it failed in step 1, there is no csrf .
We are redirected direcly to the end of step 6 and can continue there.
May be this can improve the script, for the ones hwo thought they were blocked.

Burkhard
Edit: textformating here is hell, cant place the spaces to look right. Hope you see what I mean.

Here is what I mean:(sorry, my python knowledge is verry far below basics)
if debug: print ("Step 1 ===========")
# Get initial CSRF from landing page to get login process started.
# Python Session handles JSESSIONID cookie
landing_page_url = base_url + '/portal/en_GB/web/guest/home'
landing_page_response = session.get(landing_page_url, verify=False, stream=True)

    if landing_page_response.status_code != 200:
        return '', 'Failed getting to portal landing page.'
    csrf = extract_csrf(landing_page_response.text)
    if csrf == '':
        return '', 'Failed to get CSRF from landing page.'
        if landing_page_response.url != landing_page_url # we are redirected
            login_post_response=landing_page_response # set the variable used in step 6
            goto ContinueSession  # enter step 6
if debug: print("_csrf from landing page : ", csrf)
if debug: print ("Step 2 ===========")
if debug: print ("Step 6 ===========")
# Post login data to "login action 2" url
# https://identity.vwgroup.io/signin-service/v1/<client_id>/login/authenticate 
auth_request_headers['Referer'] = login_action_url
auth_request_headers['Content-Type'] = 'application/x-www-form-urlencoded'
login_data = {
    'email': email,
    'password': password,
    'relayState': login_relay_state_token,
    'hmac': hmac_token2,
    '_csrf': login_csrf,
    'login': 'true'
}
login_action2_url = auth_base_url + '/signin-service/v1/' + client_id + '/login/authenticate'
login_post_response = session.post(login_action2_url, data=login_data, headers=auth_request_headers, allow_redirects=True, verify=certverify)
if login_post_response.status_code != 200:
    return '', 'Failed to process login sequence.'
#ref2_url = login_post_response.headers.get('location') # there is no location attribute, but does not seem to matter much.

ContinueSession: # here we enter comming from step 1 if still logged in
ref2_url = login_post_response.url
portlet_code = extract_url_parameter(ref2_url, 'code')
state = extract_url_parameter(ref2_url, 'state')
if debug: print ("state found: ", state)
if portlet_code == '':
return '', 'Failed to get portlet code.'
if state == '':
return '', 'Failed to get state.'

# Step 7
if debug: print ("Step 7 ===========")

SSLError raised recently

Hi,

Recently, i get new error when i try to use this script (it works last week !) :

raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.portal.volkswagen-we.com', port=443): Max retries exceeded with url: /portal/en_GB/web/guest/home (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1076)')))

Any idea ?

InsecureRequestWarning

InsecureRequestWarning, /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/urllib3/connectionpool.py:1004: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

I know this git is not supported more, but for me i get alot of InsecureRequestWarning. My solution to this is:

import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

How ever if this is a good idea or not i cant tell since i am no python coder.

Code ist great and working. Can someone translate it to C++?

Hello!

Thank you for this great code! I am not able to write python code and want to use this in a c++ project.
Can someone translate it to C++?
I can't even get the # Request landing page and get CSFR: part working in C++.

Thank your for any help.
Burkhard Venus

Error message

Hi,

I am getting below error. Any idea about the reason?

pi@hassbian:~ $ python /home/homeassistant/.homeassistant/scripts/vw_carnet_rb1.py retrieveCarNetInfo
Traceback (most recent call last):
File "/home/homeassistant/.homeassistant/scripts/vw_carnet_rb1.py", line 206, in
url = CarNetLogin(s,CARNET_USERNAME,CARNET_PASSWORD)
File "/home/homeassistant/.homeassistant/scripts/vw_carnet_rb1.py", line 103, in CarNetLogin
ref_url = extract_redirect_url(r).replace('&', '&')
File "/home/homeassistant/.homeassistant/scripts/vw_carnet_rb1.py", line 41, in extract_redirect_url
return redurl_re.search(r.text).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

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.