Using the Request Library

Copy the token you obtained and replace it in the token variable:

import ssl
import urllib.request
from pathlib import Path
import json

# 1. Load credentials
dsid = Path("~/.ivanti_dsid").expanduser().read_text().strip()
token = "YOUR_OPENWEBUI_TOKEN"

# 2. Configure SSL without verification (equivalent to curl -k)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

# 3. Prepare the request
payload = {
    "model": "scaylegpt",
    "messages": [{"role": "user", "content": "Hello, how are you?"}]
}

# 4. Make the POST request to the chat completions API
data = json.dumps(payload, ensure_ascii=False).encode("utf-8")
req = urllib.request.Request(
    "https://extranet.scayle.es:11010/api/chat/completions",
    method="POST",
    data=data
)
req.add_header("Cookie", f"DSID={dsid}; token={token}")
req.add_header("Content-Type", "application/json")

# 5. Read the response
with urllib.request.urlopen(req, context=ctx, timeout=30) as resp:
    result = json.loads(resp.read().decode("utf-8"))
    print(result["choices"][0]["message"]["content"])