# How to use PyCall to connect to Splunk's SDK-python?

**URL:** <https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226>\
**Category:** General Usage\
**Tags:** first-steps\
**Created:** [February 5, 2020, 10:10pm UTC](https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226 "2020-02-05T22:10:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 5, 2020, 10:10pm UTC](https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226/1 "2020-02-05T22:10:44Z")

</div>

Hi

I want to connect to Splunk using a Python SDK.

This is the code in python:

```julia
import splunklib.client as client

HOST = "localhost"
PORT = 8089
USERNAME = "admin"
PASSWORD = "passwdSPLUNK"

# Create a Service instance and log in 
service = client.connect(
    host=HOST,
    port=PORT,
    username=USERNAME,
    password=PASSWORD)

# Print installed apps to the console to verify login
for app in service.apps:
    print (app.name)

```

And this is my attempt to do the same using Julia. It obviously does not work.

```julia
using PyCall
py"""
import splunklib.client as client

def Julk_Connect(x):
    service = client.connect([{'host': "localhost", 'port': 8089, 'username': "admin", 'password': x}])
    return service
"""
py"Julk_Connect"(passwdSPLUNK)

```

This is other attempt using a Module:

```julia
module MyJulk

function __init__ ()
    print("Module MyJulk loaded")
end

function Julk_Connect(port)::PyCall.PyObject
    py"""
    import splunklib.client as client

    def Julk_ConnectP(aport):
        service = client.connect([{'host': 'localhost', 'port': aport, 'username': 'admin', 'password': 'passwdSPLUNK'}])
        return service
    """
    py"Julk_ConnectP"(port)
end

end

```

Please, any clues on what am I doing wrong?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 5, 2020, 10:13pm UTC](https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226/2 "2020-02-05T22:13:55Z")

</div>

What is the error message? What if you just do

```julia
client = pyimport("splunklib.client")
service = client.connect(host="localhost", port=8089, username="admin", password="passwdSPLUNK")

```

---

<div class="post-metadata">

**Author:** ![Aizzaac](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@Aizzaac](https://discourse.julialang.org/u/Aizzaac)\
**Post date:** [February 6, 2020, 3:44pm UTC](https://discourse.julialang.org/t/how-to-use-pycall-to-connect-to-splunks-sdk-python/34226/3 "2020-02-06T15:44:58Z")

</div>

You are right!  
Your solution is better than mine.

 ![image](https://global.discourse-cdn.com/julialang/original/3X/d/6/d64db2c39da077596afd8da8448de56eb6c8d250.png)
