Splunk Dev

Help on import cryptography.x509 for splunk add-on

spammenot66
Contributor

I'm using the Splunk Add-on Builder app to create a splunk app. on the run /test page of AoB, as soon as I add in the line from cryptography.x509 import certificate_transparency it throws the error below.As soon as I remove the line, base code from AoB immediate works but i need this cryptography to be avail

Traceback (most recent call last):

  File "C:\Splunk\etc\apps\TA-test\bin\pn_testtest_1598189382_409.py", line 14, in <module>

    import input_module_pn_testtest_1598189382_409 as input_module

  File "C:\Splunk\etc\apps\TA-test\bin\input_module_pn_testtest_1598189382_409.py", line 18, in <module>

    import cryptography.x509

  File "C:\Splunk\etc\apps\TA-test\bin\ta_test\cryptography\x509\__init__.py", line 7, in <module>

    from cryptography.x509 import certificate_transparency

ImportError: cannot import name certificate_transparency

 

I've added the paackages into the bin\ta_test folder:
cffi
asn1crypto
six
pycparser

0 Karma
1 Solution

thambisetty
SplunkTrust
SplunkTrust

you should follow below while importing module into python:

for example 1:  you have certificate_transparancy.py is inside your_app\bin\ta_test

to import certificate_transparancy.py  in your python script which is in your_app\bin

from ta_test import certificate_transparancy 

 

for example 2:  you have certificate_transparancy.py is inside your_app\bin\ta_test\inside_folder

to import certificate_transparancy.py in your python script which is in your_app\bin

from ta_test.inside_folder import certificate_transparancy 
————————————
If this helps, give a like below.

View solution in original post

thambisetty
SplunkTrust
SplunkTrust

you should follow below while importing module into python:

for example 1:  you have certificate_transparancy.py is inside your_app\bin\ta_test

to import certificate_transparancy.py  in your python script which is in your_app\bin

from ta_test import certificate_transparancy 

 

for example 2:  you have certificate_transparancy.py is inside your_app\bin\ta_test\inside_folder

to import certificate_transparancy.py in your python script which is in your_app\bin

from ta_test.inside_folder import certificate_transparancy 
————————————
If this helps, give a like below.

spammenot66
Contributor

@thambisetty Thanks for the reply. The problem was I tried to copy the site-package from Anaconda (C:\ProgramData\Anaconda2\Lib\site-packages), which was stupid. The solution was to install python,  then go to the scripts folder where python was installed to use pip.exe. 

I needed to just run pip install {module}, then copy the module along with all dependencies to the my splunk app as you've noted. 

0 Karma
Get Updates on the Splunk Community!

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

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...