All Apps and Add-ons

Need help with python script

Path Finder

trying to get a script working 

import urllib.request, json
with urllib.request.urlopen("XXXXXXXXX.json") as url:
data = json.loads(
print("data received")
for item in data:
except urllib.error.URLError as e:
print(f"Request failed with error: (e)")

this works fine and fetches the data but  I need this to pass through proxy server when I try that it does not work.. any help is apprecaited.


Labels (1)
0 Karma

Path Finder

I normally use requests when handling http or rest calls with python, as I find it really useful

Requests has methods for deserialising json as well and options to configure proxies as well

you might find this helpful?

you can then handle your own exceptions based on the http response - the useless facts api is handy for testing if you want to avoid prod

if you need to handle authentication on the proxy that may be more complex


import requests

def get_content(base, route, proxies):
    url = f'{base}/{route}'
    headers = {
        'Content-Type': 'application/json'
    response = requests.get(url, headers=headers, proxies=proxies)
    return response.json()

def main():
    base = ""
    route = "api/v2/facts/random"
    http_proxy = ""
    https_proxy = ""
    ftp_proxy = ""
    proxies = {
        "http": http_proxy,
        "https": https_proxy,
        "ftp": ftp_proxy
    response = get_content(base, route, proxies)

if __name__ == "__main__":


Path Finder

Will give it try and let you know how it goes.

0 Karma
Get Updates on the Splunk Community!

Get ready to show some Splunk Certification swagger at .conf24!

Dive into the deep end of data by earning a Splunk Certification at .conf24. We're enticing you again this ...

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Now On-Demand Join us to learn more about how you can leverage Service Level Objectives (SLOs) and the new ...

Database Performance Sidebar Panel Now on APM Database Query Performance & Service ...

We’ve streamlined the troubleshooting experience for database-related service issues by adding a database ...