splunk / splunk-sdk-python

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

EventWriter is writing bytes on stdout which is not supported in python3 #274

Closed chinmay2197 closed 3 years ago

chinmay2197 commented 5 years ago

Python sys.stdout.write() does not supporting writing bytes to stdout stream In event_writer.py self._out.write(b"<stream>") at line 54 and self._out.write(b"</stream>") at line 81 In event_writer.py write_xml_document method try to write encoded xml document to stream with self._out.write(ET.tostring(document)) In event.py self._out.write(ET.tostring(document)) in write_to method

This causes ERROR in modular input ingesting event like below: TypeError: write() argument must be str, not bytes

shakeelmohamed commented 5 years ago

Thanks for the bug report @chinmay2197, we're open to a PR but currently preparing for .conf and don't have the bandwidth to investigate this further.

croncar77 commented 5 years ago

I have the same error in write_xml_document method of event_writer.py file.

It seems to work changing self._out.write(ET.tostring(document)) to self._out.write(ET.tostring(document, encoding='unicode')) in event_writer.py file

schneewe commented 5 years ago

You can also use this change (works for me): self._out.write(ET.tostring(document)) to self._out.write(ET.tostring(document).decode())

rhymefororange commented 5 years ago

Same for me. The write() function in python3 expects str and not bytes. And when I want to write and event to Splunk it just throws TypeError. Are there any clues on when this may be fixed?

ncanumalla-splunk commented 3 years ago

Related to #271

ashah-splunk commented 3 years ago

Latest release of python sdk supports Python3 along with Python2, so we would request you to use the latest version of python sdk

In the latest version, before writing the encoded XML document to stream, it is encoded through "ensure_str()" which handles the decoding of bytes before encoding the xml document while using Python3

Do let us know if the issue is resolved .