Comments (4)
Thanks for pointing out that the docs aren't clear on this. I will look into that.
The captcha is only needed once. After successful authentication, the tokens are stored in the cache.json file. Each time the script runs, it will use the cache.json file, so you do not need to reauthenticate. You do need to supply the email at all times. So the password, passcode and captcha are not needed anymore in this case.
The captcha_solver argument must be a function. Teslapy will supply one argument to the function: the svg image. Teslapy expects a string returned by the function supplying the captcha code. The docs give this example:
def solve_captcha(svg):
with open('captcha.svg', 'wb') as f:
f.write(svg)
return input('Captcha: ')
with teslapy.Tesla('[email protected]', 'starship') as tesla:
tesla.captcha_solver = solve_captcha
tesla.fetch_token()
Above you see an example of a function that will write the SVG to a file and gets the captcha code via stdin. To answer your question to directly supply a code, you can use a lambda (the underscore is there to ignore the argument):
with teslapy.Tesla(tesla_mail, tesla_pass) as tesla:
tesla.captcha_solver = lambda _: 'btBg'
tesla.fetch_token()
vehicles = tesla.vehicle_list()
Hope this helps.
from teslapy.
Thanks, but I still can't login.
The captcha is always wrong!
with teslapy.Tesla(tesla_mail, tesla_pass) as tesla:
try:
tesla.fetch_token()#to get the captcha and write as a variable (manually)
except:
import time
time.sleep(10)
captcha = str(indigo.variables[373373398].value)
tesla.captcha_solver = lambda _: captcha
tesla.fetch_token()
vehicles = tesla.vehicle_list()
Am I missing something? I have to write the captcha manually, right?
I get a different captcha for each time I run the script...
from teslapy.
Your example will not work. You need to use a callback function. If you want a webbrowser to display the captcha and use your indigo thing to get the code after 10 seconds, you should try this:
def solve_captcha(svg):
import webbrowser
import tempfile
# Use web browser to display SVG image
with tempfile.NamedTemporaryFile(suffix='.svg', delete=False) as f:
f.write(svg)
webbrowser.open('file://' + f.name)
import time
time.sleep(10)
return str(indigo.variables[373373398].value)
with teslapy.Tesla(tesla_mail, tesla_pass) as tesla:
tesla.captcha_solver = solve_captcha
tesla.fetch_token()
vehicles = tesla.vehicle_list()
fetch_token()
will call solve_captcha()
at the moment that the captcha code is required for login. Your code runs fetch_token()
twice, which will be two different sessions and that will not work.
from teslapy.
It works perfectly.
Thanks a lot!
from teslapy.
Related Issues (20)
- 429 on every sync_wake_up() call HOT 3
- last_seen() raises "Timestamp is in the future" error HOT 3
- No longer able to set Powerwall to self_consumption mode HOT 6
- Percentage Charged not updating on get_battery_data()
- Preconditioning Battery
- Authorization broken -> Always getting "Access Denied" HOT 1
- Solar panel power only updates sporadically HOT 2
- Fails to work when run in a daemon process. HOT 2
- 410 error on get_battery_data HOT 15
- 400 Client Error: time_of_use_settings
- latitude and longitude are not in drive_state HOT 3
- Selenium blocked by Tesla HOT 2
- Move to Fleet API and Tesla Vehicle Command SDK HOT 5
- I get an InvalidSchema("No connection adapters were found for 'https://owner-api.teslamotors.com/api/1/vehicles/) Exception when using vehicle.get_vehicle_data() HOT 1
- Powerwall function get_battery_data not working HOT 1
- Not able to login HOT 6
- It seems get_charge_history() API URI is no longer working? Returns 400 HOT 2
- Seems like the teslapy is no longer working with the new Tesla APIs HOT 58
- drive_state does not have latitude and longitude
- shift_state and speed stay None even during driving
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teslapy.