Login into a CA SSO/Siteminder protected site with Python Requests

While this below code is simple, it uses two important approaches:

  • utilizes a Requests Session to keep Siteminder login cookies/headers
  • it has a two step load, allowing to fill out the Siteminder form
import requests

if __name__ == "__main__":
    mysite = 'http://mysite/'
    credentials = {'USER': 'myuser', 'PASSWORD': 'mypassword'}
    s = requests.session() # use Session to keep cookies around
    page = s.get(mysite)
    s.post(page.url, data=credentials) # page.url is the Siteminder login screen
    page = s.get(mysite)
    print(page.content)
comments powered by Disqus