Giter VIP home page Giter VIP logo

Comments (4)

tdorssers avatar tdorssers commented on May 25, 2024

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.

dawiinci avatar dawiinci commented on May 25, 2024

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.

tdorssers avatar tdorssers commented on May 25, 2024

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.

dawiinci avatar dawiinci commented on May 25, 2024

It works perfectly.

Thanks a lot!

from teslapy.

Related Issues (20)

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.