<?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: Why is there error when trying to get data from REST API using Python script? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/628142#M218206</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233419"&gt;@PaulPanther&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enter data from my local Splunk -&amp;gt; script&lt;BR /&gt;Invoke it using&lt;/P&gt;&lt;P&gt;This is a config file related to using the script.&lt;/P&gt;&lt;P&gt;my splunk inputs.conf setup&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;[script://$SPLUNK_HOME/etc/apps/tmdb/bin/tmdb_upcoming.py]
disabled = false
host = MyComputer-MacBookAir.local
interval = 60.0
sourcetype = _json&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please reply if you have any other information.&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jan 2023 13:39:28 GMT</pubDate>
    <dc:creator>munang</dc:creator>
    <dc:date>2023-01-24T13:39:28Z</dc:date>
    <item>
      <title>Why is there error when trying to get data from REST API using Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/627601#M218075</link>
      <description>&lt;P&gt;I'm trying to get data by registering it as a Splunk script using Python code.&lt;/P&gt;
&lt;P&gt;But the problem only occurs when I run this code in Splunk.&lt;/P&gt;
&lt;P&gt;When I run it directly in Splunk Python locally, there is no problem,&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="munang_0-1674139023005.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23447i157017F4C367CC83/image-size/medium?v=v2&amp;amp;px=400" role="button" title="munang_0-1674139023005.png" alt="munang_0-1674139023005.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but when I run it from Splunk, I get the following error.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="munang_1-1674139051187.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/23448i60354C7E9A90FB42/image-size/medium?v=v2&amp;amp;px=400" role="button" title="munang_1-1674139051187.png" alt="munang_1-1674139051187.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error contents are as follows.&lt;/P&gt;
&lt;P&gt;Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I searched and tried using http scheme and requests.get(verift=false), but the same error occurs.&lt;/P&gt;
&lt;P&gt;There is no error when I run it locally, so it seems to be a problem when sending a request from Splunk.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If anyone knows, I'd appreciate any help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests as req
import json

def tmdb_api_call(requestURL, parameters):
    response = req.get(url=requestURL, params=parameters)
    if response.status_code != 200:
        print(response.json())
        exit()
    data = response.json()
    return json.dumps(data)


def get_upcoming_movies_by_page(api_key, page_number=1):
    requestURL = "http://api.themoviedb.org/3/movie/upcoming"
    parameters = {"api_key": api_key, "page": page_number}
    return tmdb_api_call(requestURL, parameters)


def main():
    api_key = "key"
    upcoming_movie_list = get_upcoming_movies_by_page(api_key, 1)
    data = json.loads(upcoming_movie_list)
    print(json.dumps(data["results"]))

main()&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(code from&amp;nbsp;&lt;A href="https://github.com/siddharthajuprod07/youtube" target="_blank" rel="noopener"&gt;https://github.com/siddharthajuprod07/youtube&lt;/A&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 18:23:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/627601#M218075</guid>
      <dc:creator>munang</dc:creator>
      <dc:date>2023-01-19T18:23:25Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there error when trying to get data from REST API using Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/627734#M218113</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/248607"&gt;@munang&lt;/a&gt;&amp;nbsp;What is your setup in Splunk and how do you call the script?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Jan 2023 12:42:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/627734#M218113</guid>
      <dc:creator>PaulPanther</dc:creator>
      <dc:date>2023-01-20T12:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why is there error when trying to get data from REST API using Python script?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/628142#M218206</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/233419"&gt;@PaulPanther&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Enter data from my local Splunk -&amp;gt; script&lt;BR /&gt;Invoke it using&lt;/P&gt;&lt;P&gt;This is a config file related to using the script.&lt;/P&gt;&lt;P&gt;my splunk inputs.conf setup&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;[script://$SPLUNK_HOME/etc/apps/tmdb/bin/tmdb_upcoming.py]
disabled = false
host = MyComputer-MacBookAir.local
interval = 60.0
sourcetype = _json&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please reply if you have any other information.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jan 2023 13:39:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-there-error-when-trying-to-get-data-from-REST-API-using/m-p/628142#M218206</guid>
      <dc:creator>munang</dc:creator>
      <dc:date>2023-01-24T13:39:28Z</dc:date>
    </item>
  </channel>
</rss>

