splunk / splunk-sdk-python

Splunk Software Development Kit for Python
http://dev.splunk.com
Apache License 2.0
698 stars 370 forks source link

Possible Bug with binding class request method related to GET parameters #261

Closed billmurrin closed 2 years ago

billmurrin commented 5 years ago

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 commented 5 years ago

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
ashah-splunk commented 2 years ago

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

ashah-splunk commented 2 years ago

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