Unable to get a token when accessing via Python 2.7 requests module

Hello,

After beating my head on this and quite honestly confusing myself pretty well, I’m putting this out to the list for some help.

I am able to use curl to:

  1. Get a token
  2. Use the token acquired in step 1 and issue another curl command to delete a host from inventory

I’m trying to do the same thing using a playbook I’ve written, and a Python program, specifically the requests module.
If all else fails, I can revert to using a shell script, but using Python would be my preferred route.

I’m just not sure how to structure my call.

This is my playbook:

Hey Shawn,

You’re close :slight_smile: - I think your example code is sending application/x-www-form-urlencoded

Try this:

r = requests.post(ANSIBLE_URI, json={‘username’: ANSIBLE_USER, ‘password’: ANSIBLE_PASS}, verify=False)

Ryan,

That was it!
I’m able to get a token.

“stdout”: “{"token": "f750f5f337adbe87a3d4c20e7cfa6fea4f96bbc9", "expires": "2017-12-15T04:40:39.499Z"}”,
“stdout_lines”: [
“{"token": "f750f5f337adbe87a3d4c20e7cfa6fea4f96bbc9", "expires": "2017-12-15T04:40:39.499Z"}”
]

Thank you for your help!