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

Possible illegal argument name to client.py

Open 4n6parser opened this issue 6 years ago • 1 comments

This may or may not be an issue, but wanted to throw it out there in case it was not by design. When trying to upload a local file to splunk, I want to be able to change the host, source, and sourcetype values. In the following code, I use "rename-source" to change the value.

import splunklib.client as client service = client.connect(host=HOST, port=PORT, username=USERNAME, password=PASSWORD) myindex = service.indexes["test_index"] uploadme = "C:\Python37\Splunk\test.csv" myindex.upload(uploadme, host="NewHostName", sourcetype="NewTypeName", rename-source="fixme");

This gives me the error "SyntaxError: keyword can't be an expression". If I remove the rename-source argument, the other arguments get passed fine. I believe the problem is the hyphen in the argument name. I got around the issue by changing the last line to.

myindex.upload(uploadme, **{"host" : "NewHostName", "sourcetype" : "NewTypeName", "rename-source" : "fixme"}

4n6parser avatar May 19 '20 17:05 4n6parser

@4n6parser the issue you're seeing is expected, Python variables or parameters cannot contain hyphens. Your workaround is the correct approach.

shakeelmohamed avatar May 20 '20 18:05 shakeelmohamed