This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

UTM 9 API scripting with python

Hello,

 

I am currently working on a project that involves making a script to change some config values on a Sophos UTM 9 device and I can't seem to make it work.
My main issue is that I keep getting the code 401 (unauthorized) even though I have double checked the API key and tried everything to make it work somehow.
This is what the code currently looks like:

 

 

import requests
import base64

token = "<token>"

token64 = base64.b64encode(token.encode('ascii'))

url = "<url>:4444/api/objects/network/network/"

headers = {
    'Accept': 'text/json',
    'X-RESTD-SESSION': 'close',
    'Authorization': 'Basic:'+token64.decode('ascii')
}

response = requests.request("GET", url, headers=headers)

print(response)



This thread was automatically locked due to age.
  • following solution that I found:

    instead of using the header I passed the authorization credentials with the request like that:

    response = requests.get(url,
                            headers=headers,
                            auth=('user', 'password')

    )