Example #1
0
 def api_request(self, method, path, headers={}, data=None):
     headers = dict((k.lower(), v) for k, v in headers.iteritems())
     headers['accept'] = 'application/json'
     if data is not None:
         headers['content-type'] = 'application/json'
         data = json.dumps(data)
     response = self.request(method, path, headers, data)
     return json.loads(response)
Example #2
0
 def api_request(self, method, path, headers={}, data=None):    
     headers = dict((k.lower(), v) for k, v in headers.iteritems())
     headers['accept'] = 'application/json'
     if data is not None:
         headers['content-type'] = 'application/json'
         data = json.dumps(data)
     response = self.request(method, path, headers, data)
     return json.loads(response)
Example #3
0
 def request(self, method, path, headers={}, data=None):
     auth_headers = sign_request(key=self.key, http_method=method,
         path=self.parsed_url.path+path.split('?', 1)[0], body=data,
         host=self.parsed_url.netloc, timestamp=datetime.datetime.utcnow(),
         user_id=self.client)
     headers = dict((k.lower(), v) for k, v in headers.iteritems())
     headers['x-chef-version'] = self.version
     headers.update(auth_headers)
     try:
         response = self._request(method, self.url+path, data, dict((k.capitalize(), v) for k, v in headers.iteritems()))
     except urllib2.HTTPError, e:
         err = e.read()
         try:
             err = json.loads(err)
             raise ChefServerError.from_error(err['error'], code=e.code)
         except ValueError:
             pass
         raise
Example #4
0
 def request(self, method, path, headers={}, data=None):
     auth_headers = sign_request(key=self.key,
                                 http_method=method,
                                 path=self.parsed_url.path +
                                 path.split('?', 1)[0],
                                 body=data,
                                 host=self.parsed_url.netloc,
                                 timestamp=datetime.datetime.utcnow(),
                                 user_id=self.client)
     headers = dict((k.lower(), v) for k, v in headers.iteritems())
     headers['x-chef-version'] = self.version
     headers.update(auth_headers)
     try:
         response = self._request(
             method, self.url + path, data,
             dict((k.capitalize(), v) for k, v in headers.iteritems()))
     except urllib2.HTTPError, e:
         err = e.read()
         try:
             err = json.loads(err)
             raise ChefServerError.from_error(err['error'], code=e.code)
         except ValueError:
             pass
         raise