2

I saw this post - Passing csrftoken with python Requests

I've been working through it trying to make it work for Greenhouse. I'm trying to build a script that will automate profile creation.

I can fetch data using GET and cookies, but I think I'm I'm getting stuck with X-CSRF. I downloaded the Live HTTP headers plugin for Mozilla to get the CSRF token, but I'm unsure how to pass it in.

So far what I have:

csrf = 'some_csrf_token'
cookie = 'some_cookie_id'
data = dict('person_first_name'='Morgan') ## this is submitting my name on the form
url = 'https://app.greenhouse.io/people/new?hiring_plan_id=24047'  ##submission form page
headers = {'Cookie':cookie}

r = requests.post(url, data=data, headers=headers)

Any thoughts how I should construct my requests.post?

Community
  • 1
  • 1
Morgan Allen
  • 3,291
  • 8
  • 62
  • 86

1 Answers1

0

If you want requests to handle the cookies for you, you should set a session.

session = requests.session()
logindata = {'authenticity_token': 'whatevertokenis', 
    'user[email]': 'your@loginemail.com', 
    'user[password]': 'yourpassword',
    'user[remember_me]': '0'}    
login = session.post('https://app.greenhouse.io/users/sign_in', data=logindata) #this should log in in, i don't have an account there to test.
data = dict('person_first_name'='Morgan')
url = 'https://app.greenhouse.io/people/new?hiring_plan_id=24047'
r = session.post(url, data=data) #unless you need to set a user agent or referrer address you may not need the header to be added. 
mnjeremiah
  • 261
  • 3
  • 9
  • @mnjermiah i'm still stuck at the login screen doing that :-( – Morgan Allen Aug 19 '14 at 14:44
  • @MorganAllen Well you need to log in first... you should be passing authenticity_token, user[email], user[password], user[remember_me] via post to app.greenhouse.io/users/sign_in before you can go to the page you want.... you need to be signed in to access that page. – mnjeremiah Aug 19 '14 at 18:25