Skip to main content

Python HTTP API Example

Use the upstream Python example when an integration needs to send PTZOptics HTTP API commands with requests and HTTP Digest authentication.

  • Protocol: HTTP API
  • Language: Python
  • Task: Connect to a camera, authenticate, and send configured movement commands
  • Upstream source: example-http.py
  • License: MIT

Prerequisites​

Install Python and the requests package, then update the camera host and credentials in the upstream example before running it. See HTTP API getting started for CGI paths, command conventions, and camera HTTP Authentication.

Documentation excerpt​

The upstream example configures a reusable session with HTTPDigestAuth, then sends the exact CGI path for each command:

import requests
from requests.auth import HTTPDigestAuth

session = requests.Session()
session.auth = HTTPDigestAuth("USERNAME", "PASSWORD")
response = session.get(
"http://CAMERA-IP-ADDRESS/cgi-bin/ptzctrl.cgi?ptzcmd&rightup&15&13",
timeout=10,
)
response.raise_for_status()

This is a documentation excerpt, not the complete upstream source. Use the complete Python example for its connection test, command cycle, and error handling.

Ask PTZOptics AI

Ask a question about PTZOptics products or documentation.