alibaba82
13 years agoSuper Contributor
Cannot make simple REST call to API
Hello,
I am in the process of converting some python code that calls a REST webservice to soapUI test case. For some reason each time I try to call the webservice, I get a pop up 'Authentication Required' (see screenshot). The python code works without a problem. I am not sure what I am doing wrong here. I have tried passing the params as query, post body, etc with no success. This is quite urgent!
This is the python code
The output of
I have attached the soapui project for reference
Thanks
Ali
I am in the process of converting some python code that calls a REST webservice to soapUI test case. For some reason each time I try to call the webservice, I get a pop up 'Authentication Required' (see screenshot). The python code works without a problem. I am not sure what I am doing wrong here. I have tried passing the params as query, post body, etc with no success. This is quite urgent!
This is the python code
def test_update_changepassword (self):
response, content = self.rest.make_request('POST', self.rest_endpoint_admin, 'password=changeme')
def make_request(self, method, uri, body='', urlparam=''):
'''
Make a HTTP request to an endpoint
@type method: string
@param method: HTTP valid methods: PUT, GET, POST, DELETE
@type uri: string
@param uri: URI of the REST endpoint
@type body: string or dictionary or a sequence of two-element tuples
@param body: the request body
@type urlparam: string or dictionary or a sequence of two-element tuples
@param urlparam: the URL parameters
>>> r = SplunkRest('https://localhost:8089')
>>> r.make_request('POST', '/services/receivers/simple', urlparam={'host': 'foo'}, body="my event")
'''
if type(body) != str:
body = urllib.urlencode(body)
if type(urlparam) != str:
urlparam = urllib.urlencode(urlparam)
if urlparam != '':
url = "%s%s?%s" % (self.uri_base, uri, urlparam)
else:
url = "%s%s" % (self.uri_base, uri)
try:
response, content = self.http.request(url, method, body=body, headers=self.headers)
except ssl.SSLError, se:
raise AssertionError, "ssl.SSLError (REST call hangs): %s" % str(se)
request = {'method': method, 'url': url, 'body': body,
'auth': '%s:%s' % (self.username, self.password), 'header': self.headers}
self.logger.info("Request => %s" % request)
return response, content
The output of
self.logger.info("Request => %s" % request)is
Request => {'body': 'password=changeme', 'url': 'https://127.0.0.1:8089/services/authentication/changepassword/admin', 'method': 'POST', 'auth': 'admin:changeme', 'header': {'content-type': 'text/xml; charset=utf-8'}}
I have attached the soapui project for reference
Thanks
Ali