Skip to content

Authorization

The Public API doesn't expose all useful functions. The UI API connector fills this gap.

Code example
import asyncio
from ptsandbox import Sandbox, SandboxKey

async def main():
    key = SandboxKey(
        name="test-key-1",
        key="<TOKEN_FROM_SANDBOX>",
        host="10.10.10.10",
        ui=SandboxKey.UI(
            login="login",
            password="password",
        ),
    )

    sandbox = Sandbox(key)
    await sandbox.ui.authorize() # (1)!

asyncio.run(main())
  1. You must log in before using the API.

Sometimes you need to use the UI API without Public API access. Initialize the key like this:

Code example
import asyncio
from ptsandbox import Sandbox, SandboxKey

async def main():
    key = SandboxKey(
        name="test-ui-1",
        key="", # (1)!
        host="10.10.10.10",
        ui=SandboxKey.UI(
            login="login",
            password="password",
        ),
    )

    sandbox = Sandbox(key)
    await sandbox.ui.authorize()
  1. Just pass an empty key field

ptsandbox.sandbox.ui.SandboxUI.authorize async

authorize() -> None

Authorization in the UI using the passed parameters in the key

Raises:

  • SandboxException

    if the authorization location cannot be retrieved or login fails

  • ClientResponseError

    if the server returns an error status during login

  • ClientError

    on connection or transport errors