Script doesn't autorizate in strava.com
Question: I want to login in strava.com with python. I try do it (using
<http://www.youtube.com/watch?v=eRSJSKG4mDA>), but i can't...

    
    
    import requests
    import bs4
    with requests.Session() as c:
      url='https://strava.com/login'
      url_p='https://strava.com/session'
      Email='obichnii@yahoo.com'
      Password='12345678'
      html = c.get(url,verify=True)
      soup = bs4.BeautifulSoup(html.text)
      loginForm = soup.find('form', {'id': 'login_form'})
      hiddenAuthKey = soup.find('input', {'name': 'authenticity_token'})['value']
      print hiddenAuthKey
      login_data=dict(utf8="True",authenticity_token=hiddenAuthKey,plan='',email=Email,password=Password,remember_me='on')
      c.post(url_p,data=login_data,headers={"Referer":"https://www.strava.com/"},verify=True)
      page = c.get('https://www.strava.com/dashboard/new/web',verify=True)
      f=codecs.open('st.html','wb')
      f.write(page.content)
      f.close()
    


Answer: It is much easier if, instead of using requests, you use
[`mechanize`](http://wwwsearch.sourceforge.net/mechanize/).

    
    
    >>> import mechanize
    >>> br = mechanize.Browser()
    >>> response = br.open('https://strava.com/login')
    >>> br.select_form(nr=0)    # selects the first form on the login page
    

View the form's fields:

    
    
    >>> print br.form
    <POST https://www.strava.com/session application/x-www-form-urlencoded
      <HiddenControl(utf8=✓) (readonly)>
      <HiddenControl(authenticity_token=XgZFBcwDxCfax4AOGoDCjMYjVvM6X/iB6nSH/Cp1Um4=) (readonly)>
      <HiddenControl(plan=) (readonly)>
      <TextControl(email=)>
      <PasswordControl(password=)>
      <CheckboxControl(remember_me=[on])>
      <SubmitButtonControl(<None>=) (readonly)>>
    

Set the required values for username and password:

    
    
    >>> br.form['email'] = 'obichnii@yahoo.com'
    >>> br.form['password'] = 'xxxxxxxx'
    >>> print br.form
    <POST https://www.strava.com/session application/x-www-form-urlencoded
      <HiddenControl(utf8=✓) (readonly)>
      <HiddenControl(authenticity_token=XgZFBcwDxCfax4AOGoDCjMYjVvM6X/iB6nSH/Cp1Um4=) (readonly)>
      <HiddenControl(plan=) (readonly)>
      <TextControl(email=obichnii@yahoo.com)>
      <PasswordControl(password=xxxxxxxx)>
      <CheckboxControl(remember_me=[on])>
      <SubmitButtonControl(<None>=) (readonly)>>
    

And submit the form:

    
    
    >>> response = br.submit()
    

You should now be logged in...

    
    
    >>> print br.geturl()
    https://www.strava.com/dashboard/new/web
    

You can save the page to a file:

    
    
    with open('st.html', 'w') as f:
        f.write(response.read())
    

Note also that you have posted a working login and password, you might want to
change your password to prevent undesired logins.

