Interacting with RTC using OSLC, Python, and requests lib
30/08/2012
I recently needed to store all comments from a list of all work items from a project I was hosting on jazz.net/hub the predecessor of hub.jazz.net and always wanted to write something similarly to git to interact with jazz (started working on it on github (project link)).
I first tried to emulate the interaction as shown on their github integrator which is overly complicated then I stumbled across a library by Kenneth Reitz for doing http requests.
Using that lib the whole authentication and interactions becomes very easy:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
user= 'your jazz username' | |
pw = 'your jazz password' | |
host = 'https://jazzhost:port/something'#/ROOTSERVICES | |
resource_uri = 'https://jazzhost:port/some_uri.json' | |
r = requests.get(host + '/authenticate/identidty', headers={'Accept':'application/xml'}, allow_redirects=True, verify=False) | |
r = requests.post(host + '/j_security_check', allow_redirects=True, verify=False, data={'j_username':user,'j_password':pw}, cookies=r.cookies) | |
r = requests.get( resource_uri, allow_redirects=True, verify=False, cookies=r.cookies) | |
r.json# contains the json response as dictionary of lists/diciotnaries |
Have fun.
I tried this, but some reason this didn’t work. What I ended up doing was sessions.
s = requests.Session()
s.post(host + ‘/j_security_check’, allow_redirects=True, verify=False, data={‘j_username’:user,’j_password’:pw})
r = s.get(resource_uri, allow_redirects=True, verify=False)
r.json
I tried this, but some reason this didn’t work. What I ended up doing was sessions.
s = requests.Session()
s.post(host + ‘/j_security_check’, allow_redirects=True, verify=False, data={‘j_username’:user,’j_password’:pw})
r = s.get(resource_uri, allow_redirects=True, verify=False)
r.json
thanks for the comment, I guess the post is rather old and things might have changed in the meantime