splunk / splunk-sdk-python

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

xml.etree.ElementTree.ParseError: syntax error: line 1, column 0 #311

Closed x64Eddie closed 4 years ago

x64Eddie commented 4 years ago

Hello guys, I am new to Splunk and trying to get familiar with the SDK. I am trying to run the examples in the SDK, however, it's giving this error when running any of the examples and the python3 setup.py test

Error

~/Documents/SchoolProjects/splunk-sdk-python/examples(master*) » python3 info.py          
Traceback (most recent call last):
  File "info.py", line 34, in <module>
    service = client.connect(**opts.kwargs)
  File "../splunklib/client.py", line 331, in connect
    s.login()
  File "../splunklib/binding.py", line 886, in login
    session = XML(body).findtext("./sessionKey")
  File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/xml/etree/ElementTree.py", line 1320, in XML
    parser.feed(text)
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

.splunkrc

# Splunk host (default: localhost)
host=localhost
# Splunk admin port (default: 8089)
port=8089
# Splunk username
username=admin
# Splunk password
password=12345678
# Access scheme (default: https)
scheme=http
# Your version of Splunk (default: 5.0)
version=5.0

Test

python3 setup.py test
...
Ran 99 tests in 4.017s
FAILED (failures=1, errors=94)
fantavlik commented 4 years ago

Hey there @x64Eddie I'm not able to reproduce this with Python 3.8 and Splunk 8.0. .splunkrc

# Splunk host (default: localhost)
host=localhost
# Splunk admin port (default: 8089)
port=8089
# Splunk username
username=admin
# Splunk password
password=XXXXXXX
# Access scheme (default: https)
scheme=https
# Your version of Splunk (default: 5.0)
version=8.0
fantavlik commented 4 years ago

Closing this as we generally only support the latest major versions of Splunk, for example our test matrix runs against Splunk 8.0, 7.2, and 7.0. I'm not sure if you're running Splunk 5.0 or just hadn't updated the .splunkrc file. Please let us know if you have additional questions.

naisanzaa commented 4 years ago

I'm getting the same thing

splunk-sdk==1.6.13

import splunklib.client as client

client.connect(
            host=self.config.host,
            port=self.config.port,
            username=self.config.username,
            password=self.config.password)

Error:

>>> client.connect(
...             host=self.config.host,
...             port=self.config.port,
...             username=self.config.username,
...             password=self.config.password)
Traceback (most recent call last):
  File "/snap/pycharm-community/211/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<string>", line 1, in <module>
  File "/home/jon/venv/python3/lib/python3.8/site-packages/splunklib/client.py", line 331, in connect
    s.login()
  File "/home/jon/venv/python3/lib/python3.8/site-packages/splunklib/binding.py", line 886, in login
    session = XML(body).findtext("./sessionKey")
  File "/usr/lib/python3.8/xml/etree/ElementTree.py", line 1320, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

splunk config:

class SplunkConfig:
    def __init__(self, host: str = os.getenv('SPLUNK_HOST'),
                 port: int = os.getenv('SPLUNK_PORT'),
                 username: str = os.getenv('SPLUNK_USERNAME'),
                 password: str = os.getenv('SPLUNK_PASSWORD')):

        self.host = host if host else 'splunkcloud.com'
        self.port = port if port else 8090
        self.username = username if username else ''
        self.password = password if password else ''

The response body isn't xml, it's html: b'<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta http-equiv="refresh" content="1;url=https://server/en-US/services/auth/login"><title>303 See Other</title></head><body><h1>See Other</h1><p>The resource has moved temporarily <a href="https://server/en-US/services/auth/login">here</a>.</p></body></html>\r\n'