Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had the same problem with accessing Jira REST. Here is what worked for me:</p> <pre><code>class JiraOpenerWrapper(object): # Class to wrap urllib2 OpenerDirector to add authenication headers. # this is needed fro Jira - see comment below. def __init__(self, opener, user, password): self.opener = opener self.user = user self.password = password def open(self, url, data, timeout): if isinstance(url, str): # if given a url - create a request and add req = urllib2.Request(url, data, { "Authorization": "Basic " + base64.b64encode( self.user + ":" + self.password) }) else: req = url return self.opener.open(req, data, timeout) def __getattr__(self, attr): if attr == "open": return self.open return getattr(self.opener, attr) def RegisterPasswords(user, password): password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm() password_manager.add_password( None, 'https://rt.mycorp.site/', user, password) password_manager.add_password( None, 'https://jira.mycorp.site/', user, password) auth_handler = urllib2.HTTPBasicAuthHandler(password_manager) opener = urllib2.build_opener(auth_handler) # Jira has a strage behviour - it does not return the proper error # when sending a request without an Authentication header. # This causes Python's urllib2 not to retry with the pass word. # For Jira we would need to add the headers all the time jira_opener = JiraOpenerWrapper(opener, user, password) urllib2.install_opener(jira_opener) def GameJira(): url = "https://jira.mycorp.site/rest/api/2/issue/PRJ-123" data = urllib2.urlopen(url, None).read() print "Jira:\n", data </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload