Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 compatibility #18

Open
s-m-p opened this issue Sep 1, 2020 · 10 comments
Open

Python3 compatibility #18

s-m-p opened this issue Sep 1, 2020 · 10 comments

Comments

@s-m-p
Copy link

s-m-p commented Sep 1, 2020

I wanted to bring awareness that v1.1.1 of the TA doesn't seem to run with Python3 on Splunk version 8.0.5. I'm not a programmer, but it appears there's an incompatibilty in one of the libraries.
> splunk cmd python3 asngen.py
Traceback (most recent call last):
File "asngen.py", line 3, in
from splunklib.searchcommands import dispatch, GeneratingCommand, Configuration, Option, validators
File "/opt/splunk/etc/apps/TA-asngen/bin/splunklib/searchcommands/init.py", line 145, in
from .environment import *
File "/opt/splunk/etc/apps/TA-asngen/bin/splunklib/searchcommands/environment.py", line 21, in
from os import chdir, environ, getcwdu, path
ImportError: cannot import name 'getcwdu' from 'os' (/opt/splunk/lib/python3.7/os.py)

@s-m-p s-m-p closed this as completed Sep 1, 2020
@s-m-p s-m-p reopened this Sep 1, 2020
@s-m-p
Copy link
Author

s-m-p commented Sep 1, 2020

Not sure how it was closed, I did not intend to do that. Sorry.

@doksu
Copy link
Owner

doksu commented Sep 2, 2020

I've just tested v1.1.1 and definitely works on Splunk 8.0.5

@s-m-p
Copy link
Author

s-m-p commented Sep 2, 2020

Thank you for attempting to test. Was your test system configured for Python3?

I apologize if I should have included this information up front. Splunk included the Python3 libraries in version 8, but they did not yet make Python3 the default (though that will come in some future release). To change the default version of Splunk, you must add the 'python.version' attribute to the server.conf:

[general]
python.version = python3

To prevent overriding this at the app level, you can force it:

[general]
python.version = force_python3

You can override python.version = python3 in server.conf at the app level in commands.conf

[asngen]
filename = asngen.py
chunked = true
python.version = python2

If you add python.version = python3 to commands.conf, you should see the error I attached.

@s-m-p
Copy link
Author

s-m-p commented Sep 2, 2020

I'm sure everyone knows this too, but this is the document that explains how to control the python version:
Changes to Splunk Enterprise

@s-m-p
Copy link
Author

s-m-p commented Sep 2, 2020

I thought I might mention another way to reproduce the error. If you have command-line access to Splunk, you can also run the script with python2 or python3:
splunk cmd python2 asngen.py (no error)
splunk cmd python3 asngen.py (error)

@doksu
Copy link
Owner

doksu commented Sep 4, 2020

Thanks very much @s-m-p. I mistakenly thought that Splunk 8.0 used Python 3 as the default and so my tests were invalid. Although the app works fine in Splunk 8.0 by default, I've now removed the Splunk 8.0 compatibility on Splunkbase for this app so it cannot be misconstrued as working with Python 3. I will endeavour to make both this and my other apps using Python compatible with version 3 in the near future.

@s-m-p
Copy link
Author

s-m-p commented Sep 4, 2020

You're most welcome. Thank you very much for developing, sharing and supporting the TA! And I'm happy to see my first Github interaction was a positive contribution.

I've now removed the Splunk 8.0 compatibility on Splunkbase for this app so it cannot be misconstrued as working with Python 3.

This answered another question I have been asking myself - how in the world did this TA get marked as compatible with 8.0? It sounds like this is a flag that you can set when you publish the app to Splunkbase. So I'm happy to hear you plan to remove that flag because it definitely confused me.

I'll be happy to give your updated TA a test if you need a beta tester!

@kurtkeller
Copy link
Contributor

The changes in pull request #19 make it work in both, python2 and python3 environments.

@greg-savage
Copy link

The changes in pull request #19 make it work in both, python2 and python3 environments.

Thanks for the work on that.

@kurtkeller
Copy link
Contributor

@doksu : if you'd merge pull request #19 this could be closed as well; those changes have been working fine in our environment ever since I made them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants