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 illegal argument name to client.py #323

Closed 4n6parser closed 4 years ago

4n6parser commented 4 years ago

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"}

shakeelmohamed commented 4 years ago

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