- def POSTRequestToOARRestAPI(self, request,format, datadict):
- self.oarserver['uri'] = OARrequest_post_uri_dict[request]
- if format in POSTformat:
- if format is 'json':
- data = json.dumps(datadict)
-
- try :
- conn = httplib.HTTPConnection(self.oarserver['ip'],self.oarserver['port'])
- conn.putrequest("POST",self.oarserver['uri'] )
- self.oarserver['postformat'] = POSTformat[format]
- conn.putheader('content-type', self.oarserver['postformat']['content'])
- conn.putheader('content-length', str(len(data)))
- conn.endheaders()
- conn.send(data)
- resp = ( conn.getresponse()).read()
- conn.close()
+ def POSTRequestToOARRestAPI(self, request, datadict, username):
+ #first check that all params for are OK
+ print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI username",username
+ try:
+ self.oarserver['uri'] = OARrequest_post_uri_dict[request]
+ except:
+ print>>sys.stderr, " \r\n \r\n POSTRequestToOARRestAPI request not in OARrequest_post_uri_dict"
+ return
+ #if format in POSTformat:
+ #if format is 'json':
+ data = json.dumps(datadict)
+ headers = {'X-REMOTE_IDENT':username,\
+ 'content-type':POSTformat['json']['content'],\
+ 'content-length':str(len(data))}
+ try :
+ #self.oarserver['postformat'] = POSTformat[format]
+
+ print>>sys.stderr, "\r\n POSTRequestToOARRestAPI headers %s uri %s" %(headers,self.oarserver['uri'])
+ conn = httplib.HTTPConnection(self.oarserver['ip'],self.oarserver['port'])
+ conn.request("POST",self.oarserver['uri'],data,headers )
+ resp = ( conn.getresponse()).read()
+ conn.close()
+
+ #conn = httplib.HTTPConnection(self.oarserver['ip'],self.oarserver['port'])
+ #conn.putrequest("POST",self.oarserver['uri'] )
+ #self.oarserver['postformat'] = POSTformat[format]
+ #conn.putheader('HTTP X-REMOTE_IDENT', 'avakian')
+ #conn.putheader('content-type', self.oarserver['postformat']['content'])
+ #conn.putheader('content-length', str(len(data)))
+ #conn.endheaders()
+ #conn.send(data)
+ #resp = ( conn.getresponse()).read()
+ #conn.close()