Getting Data In

How to connect to external lookup using Python script?

nnimbe1
Path Finder

We were using below script to connect and download csv and store it in folder. But now website has changed and it asks for the username and password. Can somebody suggests any required changes where we can connect to URL, Authenticate with username and password, and download the file?

import os

import urllib2

response = urllib2.urlopen('URL')

data = response.read()

filename = os.path.join(os.environ['SPLUNK_HOME'], 'etc', 'apps', 'SPLAPP', 'lookups', "Splunk_Monitored_Hosts.csv")

file_ = open(filename, 'w')

file_.write(data)
#file_.close()
0 Karma

jpass
Contributor

I know this is a bit old but here's how I authenticate with Basic HTTP Auth:

import requests
from requests.auth import HTTPBasicAuth

username = "<user>"
apikey = "<pass>"
apiurl = "<theurlyouconnectto>"

with requests.Session() as s:
    s.auth = (username,apikey)
    r = s.get(apiurl)    
0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...