Splunk Dev

Authentication error while running python script with office365 module.

darljed
Explorer

Hi guys,

Need help. I am trying to create a custom python script with has a dependecy on office365 (https://github.com/vgrem/Office365-REST-Python-Client) module. The script was creating REST API calls to SharePoint to update, delete, add items to it. I am using client ID and client secret as Credentials to access SharePoint. The script will be triggered by a Scheduled Search.

I placed the file on $SPLUNK_HOME/etc/apps/<appname>/bin/ both the script and the office365 folder.

When I try to run the script using python scriptName.py on that directory, It is working fine so I expected that It will work the same when the script was triggered from Splunk. But no. I am getting authentication error.

Traceback (most recent call last):
  File "sharepoint_fetch_data.py", line 100, in <module>
    print ("ingestion error: {0}".format(ctx_auth.get_last_error()))
  File "/opt/splunk/etc/apps/sharepoint_connector/bin/office365/runtime/auth/authentication_context.py", line 37, in get_last_error
    return self.provider.get_last_error()
AttributeError: 'ACSTokenProvider' object has no attribute 'get_last_error'

Which I am not getting when I run It using python scriptName.py only.

I also tried to run the script using $SPLUNK_HOME/bin/splunk cmd python scriptName.py and the errors were the same. It seems that I am getting the error when running it with Splunk's python. Like blocking the connection or something... I don't know.

Did I missed to do or configure something ? Please help me. Thanks in advance!!

Labels (2)
Tags (2)
0 Karma
1 Solution

DavidHourani
Super Champion

Hi @darljed,

It seems like the Splunk Python could be missing some of the functions used by that script. Try updating your script to make it use the system's python :
https://stackoverflow.com/questions/3108285/in-python-script-how-do-i-set-pythonpath
This should solve your problem.

PS: This could also be because you're running the script as root and Splunk is running it as the Splunk user ?

Cheers,
David

View solution in original post

0 Karma

darljed
Explorer

I got the fix now 🙂
https://answers.splunk.com/answers/2821/python-scripted-inputs-run-with-the-wrong-version-of-python-...

So I just need to create a shell script to trigger my python script.

0 Karma

DavidHourani
Super Champion

Hi @darljed,

It seems like the Splunk Python could be missing some of the functions used by that script. Try updating your script to make it use the system's python :
https://stackoverflow.com/questions/3108285/in-python-script-how-do-i-set-pythonpath
This should solve your problem.

PS: This could also be because you're running the script as root and Splunk is running it as the Splunk user ?

Cheers,
David

0 Karma

darljed
Explorer

I guess you're right about Splunk's python could be missing something... I also tried setting up sys.path but still it will use Splunk's Python.

0 Karma

darljed
Explorer

Thanks Anyway 🙂

0 Karma

DavidHourani
Super Champion

You're welcome. I also checked the git repository you linked. It seems that get_last_error is in office365/runtime/auth/authentication_context.py did you grab the entire repository or just the files you need ? Could be a good idea to import the whole thing and try it out with all the code there.

0 Karma

darljed
Explorer

Yes, I downloaded Everything and Imported the needed resources. It was actually working when running outside Splunk so It means that there are no problem with the package.

But luckily, I got the fix now 🙂

https://answers.splunk.com/answers/2821/python-scripted-inputs-run-with-the-wrong-version-of-python-...

I just need to create a shell script to trigger my python script from outside Splunk's Python..

DavidHourani
Super Champion

Awesome ! 🙂

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...