Forum Discussion

alibaba82's avatar
alibaba82
Super Contributor
13 years ago

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

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

4 Replies

  • Hi,

    If you click the "Aut" tab in the login request form, you can input your login credentials. That way you won't have to input them manually each time you run the test.

    I've attached a screenshot below showing where you can find this setting.

    --
    Regards

    Arian
    SmartBear Sweden
  • alibaba82's avatar
    alibaba82
    Super Contributor
    Hi Arian,
    I believe that is not the issue. The /changepassword call only requires a 'sessionkey' header which I have already specified. If you notice the python code, there is no authentication details passed

    Ali
  • alibaba82's avatar
    alibaba82
    Super Contributor
    Hi Arian,
    Here is the curl command that can make the REST call easily.

    araza-mba13:test araza$ curl -k -u admin:changeme https://localhost:8089/services/authent ... word/admin -d password=foobar

    Do you think you can send me a sample soapUI project which this endpoint and a simple test case ? This would really help me out.

    Thanks

    Ali