Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register
  • We just completed a significant update, but we still have some fixes and adjustments to make, so please bear with us for the time being. Cheers!

Generate V3 Refresh Token for API Authentication using Python

CarvedArt

Member
Aug 12, 2020
12
7
Mars
There is already a nice little method on here using PHP created by MrTemple. I saw a few comments from people struggling to get it configured so I figured I'd document a simple step-by-step method using Python as an alternative.


*NOTE: This guide assumes Python is not already installed and Windows is your operating system. (These steps can be easily adjusted/followed on Linux and MacOS.)


PREREQUISITES:


STEPS:

  1. Download the prerequisites
  2. Create a project folder to store your files; e.g., “C:\Users\Username\Desktop\TeslaTokens”
  3. Place: ChromeDriver, auth.tokens.py, and requirements.txt in “C:\Users\Username\Desktop\TeslaTokens”
  4. Install Python FOR ALL USERS and add to PATH (If you need help installing Python there are plenty of great videos out there explaining the process for each system)
  5. Launch a command window/terminal (e.g., PowerShell, Command Prompt, Terminal, etc.)
  6. Type:
    Code:
    CD C:\Users\Username\Desktop\TeslaTokens
  7. Press: ENTER
  8. Type:
    Code:
    pip install -r requirements.txt
  9. Press: ENTER
  10. At this point everything should be installed, configured and ready to go
  11. Then enter one of the below strings at the command prompt and hit ENTER:

If your Tesla account has MFA enabled:
Code:
python3 ./auth.tokens.py -u 'email' -p 'password' -c 'passcode'

If your Tesla account does not have MFA enabled:
Code:
python3 ./auth.tokens.py -u 'email' -p 'password'

-u = Tesla account email
-p = Tesla account password
-c = Passcode generated by your authenticator app

MFA example:
Code:
python3 ./auth.tokens.py -u my[email protected] -p someSuperSecurePassword -c 123456

Non-MFA example:
Code:
python3 ./auth.tokens.py -u [email protected] -p someSuperSecurePassword

TIPS:

  • If python3 does not work try using just python
  • To check your Python install you can type:
    Code:
    python --version
 
  • Like
Reactions: manddarran

About Us

Formed in 2006, Tesla Motors Club (TMC) was the first independent online Tesla community. Today it remains the largest and most dynamic community of Tesla enthusiasts. Learn more.

Do you value your experience at TMC? Consider becoming a Supporting Member of Tesla Motors Club. As a thank you for your contribution, you'll get nearly no ads in the Community and Groups sections. Additional perks are available depending on the level of contribution. Please visit the Account Upgrades page for more details.


SUPPORT TMC
Top