Skip to content

Instantly share code, notes, and snippets.

@sgwilbur
Created January 15, 2015 18:46
Show Gist options
  • Save sgwilbur/400e2373782ff39c51f5 to your computer and use it in GitHub Desktop.
Save sgwilbur/400e2373782ff39c51f5 to your computer and use it in GitHub Desktop.
Rational Team Concert Python Requests example
#!/usr/bin/env python
import requests
# quiet warnings for self-signed certificates
requests.packages.urllib3.disable_warnings()
base_url = "https://server.demo.com/ccm"
auth_uri = "/authenticated/identity"
jazz_user = "user"
jazz_pass = "secretpassword"
session = requests.Session()
session.verify = False
session.allow_redirects = True
session.headers = {'accept':'application/xml'}
session.auth = (jazz_user, jazz_pass)
print "Request for authenticated resource"
response = session.get(base_url + auth_uri)
#print response.text
print response.headers
if 'x-com-ibm-team-repository-web-auth-msg' in response.headers and response.headers['x-com-ibm-team-repository-web-auth-msg'] == 'authrequired':
print "Not currently authenticated"
# Form response
print "Sending login POST"
login_response = session.post(base_url + '/j_security_check', data={ 'j_username': jazz_user, 'j_password': jazz_pass } )
print login_response.headers
if 'x-com-ibm-team-repository-web-auth-msg' in login_response.headers and login_response.headers['x-com-ibm-team-repository-web-auth-msg'] == 'authrequired':
print "Failed to authenticate"
print login_response.status_code
print login_response.text
raise Exception( "Failed to login: ", login_response.text )
print "Getting authenticated resource again now that we should be logged in:"
response = session.get( base_url + auth_uri )
print response.headers
print response.text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment