<?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 Re: Need help with python script in All Apps and Add-ons</title>
    <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671244#M80038</link>
    <description>&lt;P&gt;I normally use requests when handling http or rest calls with python, as I find it really useful&lt;/P&gt;&lt;P&gt;Requests has methods for deserialising json as well and options to configure proxies as well&lt;/P&gt;&lt;P&gt;you might find this helpful?&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/8287628/proxies-with-python-requests-module" target="_blank"&gt;https://stackoverflow.com/questions/8287628/proxies-with-python-requests-module&lt;/A&gt;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;if you need to handle authentication on the proxy that may be more complex&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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 = "https://uselessfacts.jsph.pl"
    route = "api/v2/facts/random"
    http_proxy = "http://10.10.1.10:3128"
    https_proxy = "https://10.10.1.11:1080"
    ftp_proxy = "ftp://10.10.1.10:3128"
    
    proxies = {
        "http": http_proxy,
        "https": https_proxy,
        "ftp": ftp_proxy
    }
    response = get_content(base, route, proxies)
    print(response)


if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Dec 2023 09:35:31 GMT</pubDate>
    <dc:creator>splunkernator</dc:creator>
    <dc:date>2023-12-08T09:35:31Z</dc:date>
    <item>
      <title>Need help with python script</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671231#M80037</link>
      <description>&lt;P&gt;trying to get a script working&amp;nbsp;&lt;/P&gt;&lt;P&gt;import urllib.request, json&lt;BR /&gt;try:&lt;BR /&gt;with urllib.request.urlopen("XXXXXXXXX.json") as url:&lt;BR /&gt;data = json.loads(url.read().decode())&lt;BR /&gt;print("data received")&lt;BR /&gt;for item in data:&lt;BR /&gt;print(item)&lt;BR /&gt;except urllib.error.URLError as e:&lt;BR /&gt;print(f"Request failed with error: (e)")&lt;/P&gt;&lt;P&gt;this works fine and fetches the data but&amp;nbsp; I need this to pass through proxy server when I try that it does not work.. any help is apprecaited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 09:00:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671231#M80037</guid>
      <dc:creator>KulvinderSingh</dc:creator>
      <dc:date>2023-12-08T09:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with python script</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671244#M80038</link>
      <description>&lt;P&gt;I normally use requests when handling http or rest calls with python, as I find it really useful&lt;/P&gt;&lt;P&gt;Requests has methods for deserialising json as well and options to configure proxies as well&lt;/P&gt;&lt;P&gt;you might find this helpful?&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/8287628/proxies-with-python-requests-module" target="_blank"&gt;https://stackoverflow.com/questions/8287628/proxies-with-python-requests-module&lt;/A&gt;&lt;/P&gt;&lt;P&gt;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&lt;/P&gt;&lt;P&gt;if you need to handle authentication on the proxy that may be more complex&lt;/P&gt;&lt;P&gt;e.g.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;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 = "https://uselessfacts.jsph.pl"
    route = "api/v2/facts/random"
    http_proxy = "http://10.10.1.10:3128"
    https_proxy = "https://10.10.1.11:1080"
    ftp_proxy = "ftp://10.10.1.10:3128"
    
    proxies = {
        "http": http_proxy,
        "https": https_proxy,
        "ftp": ftp_proxy
    }
    response = get_content(base, route, proxies)
    print(response)


if __name__ == "__main__":
    main()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 09:35:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671244#M80038</guid>
      <dc:creator>splunkernator</dc:creator>
      <dc:date>2023-12-08T09:35:31Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with python script</title>
      <link>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671272#M80039</link>
      <description>&lt;P&gt;Will give it try and let you know how it goes.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Dec 2023 15:35:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/All-Apps-and-Add-ons/Need-help-with-python-script/m-p/671272#M80039</guid>
      <dc:creator>KulvinderSingh</dc:creator>
      <dc:date>2023-12-08T15:35:41Z</dc:date>
    </item>
  </channel>
</rss>

