splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

Possible Bug with binding class request method related to GET parameters

Open billmurrin opened this issue 7 years ago • 3 comments

I created a lookup on /servicesNS/-/-/data/lookup-table-files to obtain the lookup table files. I noticed that the result was limited to 30 results per request. With that in mind, I attempted to pass in parameters for output_mode=json&count=0. The following code has been modified slightly and is based on a snippet found in the invoke function of spurl.py SDK example:

return binding.connect(**kwargs).request(path, method=method, body=urllib.urlencode({'output_mode': 'json', 'count': 0}))

The output_mode works properly and returns json, however when using count (or offset), it results in a 400 error:

HTTP 400 Bad Request -- {"messages":[{"type":"ERROR","text":"Argument \"count\" is not supported by this handler."}]}

Now, if I use binding.connect(**kwargs).get and pass in the same dictionary {'output_mode': 'json', 'count' 0} it gets properly passed as part of the GET request and returns all of the records.

return binding.connect(**kwargs).get(path, **{'output_mode': 'json', 'count': 0})

I believe the desired behavior on the request method would be to allow the use of Pagination and filtering parameters.

billmurrin avatar Jul 24 '19 01:07 billmurrin

I believe the piece of code that is missing from the Context.request method is similar to portion found within the self.http.get method being called by Context.get:

        if kwargs:
            # url is already a UrlEncoded. We have to manually declare
            # the query to be encoded or it will get automatically URL
            # encoded by being appended to url.
            url = url + UrlEncoded('?' + _encode(**kwargs), skip_encode=True)
        return self.request(url, { 'method': "GET", 'headers': headers })

In Context.request, it adds body to the dict, but is not appending it to the baseURL, unlike self.http.get. Both methods appear to be calling http.request.

response = self.http.request(path,
                                     {'method': method,
                                     'headers': all_headers,
                                     'body': body})
        return response

billmurrin avatar Jul 24 '19 01:07 billmurrin

@billmurrin Thanks for the PR, we have merged the PR and the changes will be available in the next release.

ashah-splunk avatar Dec 16 '21 04:12 ashah-splunk

@billmurrin we have a new python-sdk release 1.6.19, and your changes are available in this latest release.

ashah-splunk avatar Apr 05 '22 12:04 ashah-splunk