<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic splunk client send error &amp;quot;a bytes-like object is require&amp;quot; with python script in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415466#M7231</link>
    <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;

&lt;P&gt;I am trying to upload CSV file to a certain index and a certain sourcetype (already exist in Splunk) with a python script. I have already installed Python SDK Splunk and I am using Python 3 with anaconda &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.client as client
service = client.connect(host='localhost',port=8089,username='admin',password='Passwd')
myindex = service.indexes["Index1"]
mysocket = myindex.attach(sourcetype='ST1',host='My_PC')
file_data = ''
with open("ST1_23_Mai_2018.csv", "r") as lines:
    for line in lines:
        if line.isspace(): 
            line = ' '
            file_data += line 
            file_data += '\r\n'
    mysocket.send(file_data)
mysocket.close()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The SSL handshake is successful. However, I am getting following error through python:-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; File "C:\Users\XXX\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 642, in write
    return self._sslobj.write(data)

TypeError: a bytes-like object is required, not 'str'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anyone have faced similar situation before. I try to check the splunk documentation at :  &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEE6#add2index"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEE6#add2index&lt;/A&gt;  and  &lt;A href="http://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.3/client.html#splunklib.client.Index.upload"&gt;http://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.3/client.html#splunklib.client.Index.upload&lt;/A&gt; &lt;/P&gt;</description>
    <pubDate>Wed, 23 May 2018 08:58:02 GMT</pubDate>
    <dc:creator>Chandras11</dc:creator>
    <dc:date>2018-05-23T08:58:02Z</dc:date>
    <item>
      <title>splunk client send error "a bytes-like object is require" with python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415466#M7231</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;

&lt;P&gt;I am trying to upload CSV file to a certain index and a certain sourcetype (already exist in Splunk) with a python script. I have already installed Python SDK Splunk and I am using Python 3 with anaconda &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.client as client
service = client.connect(host='localhost',port=8089,username='admin',password='Passwd')
myindex = service.indexes["Index1"]
mysocket = myindex.attach(sourcetype='ST1',host='My_PC')
file_data = ''
with open("ST1_23_Mai_2018.csv", "r") as lines:
    for line in lines:
        if line.isspace(): 
            line = ' '
            file_data += line 
            file_data += '\r\n'
    mysocket.send(file_data)
mysocket.close()
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The SSL handshake is successful. However, I am getting following error through python:-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; File "C:\Users\XXX\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 642, in write
    return self._sslobj.write(data)

TypeError: a bytes-like object is required, not 'str'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Does anyone have faced similar situation before. I try to check the splunk documentation at :  &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEE6#add2index"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEE6#add2index&lt;/A&gt;  and  &lt;A href="http://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.3/client.html#splunklib.client.Index.upload"&gt;http://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.3/client.html#splunklib.client.Index.upload&lt;/A&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 08:58:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415466#M7231</guid>
      <dc:creator>Chandras11</dc:creator>
      <dc:date>2018-05-23T08:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: splunk client send error "a bytes-like object is require" with python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415467#M7232</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;

&lt;P&gt;you're sending a string where Splunk expects bytes, a comparable situation is explained here:&lt;BR /&gt;
&lt;A href="https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t?utm_medium=organic&amp;amp;utm_source=google_rich_qa&amp;amp;utm_campaign=google_rich_qa"&gt;https://stackoverflow.com/questions/33054527/python-3-5-typeerror-a-bytes-like-object-is-required-not-str-when-writing-t?utm_medium=organic&amp;amp;utm_source=google_rich_qa&amp;amp;utm_campaign=google_rich_qa&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;I'd try to just change &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; with open("ST1_23_Mai_2018.csv", "r") as lines:
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; with open("ST1_23_Mai_2018.csv", "rb") as lines:
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 10:35:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415467#M7232</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-23T10:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: splunk client send error "a bytes-like object is require" with python script</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415468#M7233</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Thanks for the answer. I already tried to make it rb (read as bytes) but I didn't get any success.  The error is still the same. &lt;BR /&gt;
Do I need to change some properties in anaconda3\lib\ssl.py ?? &lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 10:52:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/splunk-client-send-error-quot-a-bytes-like-object-is-require/m-p/415468#M7233</guid>
      <dc:creator>Chandras11</dc:creator>
      <dc:date>2018-05-23T10:52:58Z</dc:date>
    </item>
  </channel>
</rss>

