Getting Data In

Not able to push data to splunk using python SDK

rajanishsinght
New Member

I am using below code to push data to splunk using Python SDk,script is executed successfully but i am not seeing any data in splunk.

import splunklib.client as client
service = client.connect(host='localhost',port=8089,username='username',password='password')
myindex = service.indexes["main"]
mysocket = myindex.attach(sourcetype='rajanish',host='myhost')
file_data = ''
with open("foo.txt", "r") as lines:
for line in lines:
if line.isspace():
line = ' '
file_data += line
file_data += '\r\n'
mysocket.send(file_data)
mysocket.close()

Tags (1)
0 Karma

yaseenbe
New Member

hi rajanish,

did you get this issue fixed. can you help me with the python code. i am also trying to push data to splunk.

I am new to splunk, so kindly help me

0 Karma
Get Updates on the Splunk Community!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...