Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tesla api example : failing getting the partner token #9

Open
AF-Hub opened this issue Nov 10, 2024 · 1 comment
Open

tesla api example : failing getting the partner token #9

AF-Hub opened this issue Nov 10, 2024 · 1 comment

Comments

@AF-Hub
Copy link

AF-Hub commented Nov 10, 2024

I cannot go further the step of getting the partner token.

It does not appear in the URL (node '&code=') however, a code appears in the error page with a copy button, which I used as a code. Tried several times but failed each time. Any help welcome ! Here is the trace (private info hidden):

$ python main.py

Welcome to the guided tour of the tesla_api library

Registering a developer account
Please go to the following URL and register a developer account and your app (Python program):
https://developer.tesla.com/
Press [Enter] to continue, when registration is complete or to cancel...
OpenSSL 1.1.1g FIPS 21 Apr 2020
The keys already exist in the directory 'lib/tesla_api/TeslaKeys'
Please push the public key 'lib/tesla_api/TeslaKeys/com.tesla.3p.public-key.pem' to your domain at the following URL:
https://xxxx.com/.well-known/appspecific/com.tesla.3p.public-key.pem
optional: put the php script 'tesla_api/WWW-example/index.php' to your https://xxx.com/ directory to ease the code retrieval for later customer registration
Press Enter to continue, when the public key is pushed...
Getting the partner token...
Registering the partner account and domain .com
log Debug Tesla Command url: /api/1/partner_accounts
log Debug response status: 412, Precondition Failed, {"response":null,"error":"Root domain .com must match registered allowed origin on https://developer.tesla.com/dashboard/app-details/","error_description":"","txid":""}
return value register partner account: None
Something went wrong during registration, check logging
log Error The file tesla_tokens.json was not found.
The token file does not yet exist - we register the customer account now...
web-browser opened with URL:
https://auth.tesla.com/oauth2/v3/authorize?&client_id=&locale=en-US&prompt=login&redirect_uri=https:///&response_type=code&scope=openid%20offline_access%20user_data%20vehicle_device_data%20vehicle_cmds%20vehicle_charging_cmds%20energy_device_data%20energy_cmds&state=e7002213af7560aba03a1ebc3c782ec5
complete registration and watch, if the following random number is not disturbed in the response.
e7002213af7560aba03a1ebc3c782ec5
Next step is to exchange the Code for tokens.
You find the code in the URL, the tesla server redirects you to.
The page likely shows a 400 Bad Request, this is normal
The code can be found between &code and &state in the url
Please enter the 'code' from the URL:
--- token data {'error': 'invalid_auth_code', 'error_description': 'The authorization code is invalid. It may have already been used or expired. Request a new sign in session to generate a new code.', 'referenceID': . For more information, visit: https://developer.tesla.com/docs/fleet-api#help-and-support'}
Traceback (most recent call last):
File "main.py", line 118, in
tesla_api.tesla_register_customer(myTesla)
File "lib/tesla_api/tesla_api_2024.py", line 517, in tesla_register_customer
myTesla.exchange_code_for_tokens(myTesla.client_id, CLIENT_SECRET, user_input_code)
File "lib/tesla_api/tesla_api_2024.py", line 165, in exchange_code_for_tokens
expiry_time = datetime.datetime.now() + datetime.timedelta(seconds=token_data.get('expires_in'))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported type for timedelta seconds component: NoneType
$

@PRRoutley
Copy link

It looks like you got earlier errors:

log Debug response status: 412, Precondition Failed, {"response":null,"error":"Root domain .com must match registered allowed origin on https://developer.tesla.com/dashboard/app-details/","error_description":"","txid":""}

I managed to get it working a few days ago, but the instructions regarding '/'s in config.py seemed the wrong way around for the lines 13 and 14: tesla_redirected_domain and tesla_redirect_uri
I ended up with the format below:

tesla_redirect_domain = "xxx.yyy.zzz/" # NO https:// !!!
tesla_redirect_uri = "https://xxx.yyy.zzz/cgi-bin/ProcessToken.py" # start with https:// and include a tailing '/'!

I do not speak php so used a python script to extract my token but index.php should work just as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants