# Python (requests)

{% code lineNumbers="true" %}

```
"""
HOW TO RUN:
1. Ensure you have Python installed.
2. Install the required dependency 'httpx' by running:
   pip install httpx
3. Save this file as 'scan_trust.py'.
4. Run the script:
   python scan_trust.py
"""

import httpx
import json

API_BASE_URL = "https://trust-sse.oten.com"
API_KEY = "ot_live_-d5Il4kuuv..."
URL_TO_SCAN = "https://google.com"

def scan_url(url: str, lang: str = "en"):
    with httpx.Client(timeout=120.0) as client:
        with client.stream(
                "GET",
                f"{API_BASE_URL}/api/v1/scan-url",
                params={"url": url, "lang": lang},
                headers={"Authorization": f"Bearer {API_KEY}"},
        ) as response:
            print(f"Status: {response.status_code}")
            print(f"Headers: {dict(response.headers)}\n")

            for line in response.iter_lines():
                if not line:
                    continue

                if line.startswith("event:"):
                    event_type = line.split(":", 1)[1].strip()
                    print(f"[{event_type}]", end=" ")

                elif line.startswith("data:"):
                    data_str = line.split(":", 1)[1].strip()
                    try:
                        data = json.loads(data_str)
                        print(json.dumps(data, indent=2, ensure_ascii=False))
                    except json.JSONDecodeError:
                        print(data_str)

                elif line.startswith("id:"):
                    event_id = line.split(":", 1)[1].strip()
                    print(f"id={event_id}")


if __name__ == "__main__":
    scan_url(URL_TO_SCAN)
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://oten.gitbook.io/oten-trust-support/documentation/api-reference/code-samples/python-requests.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
