Skip to content

BLS

import requests


def fetch_ocr_result():
    url = "https://api.example.com/ocr"  # Replace with the actual API endpoint
    headers = {"Content-Type": "application/json"}

    data = {
        "apiKey": "sonic_xxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "task": {
            "type": "OcrImage",
            "screenshot": True,
            "queries": [],
            "numeric": True,
            "module": "",
            "case": True,
            "maxLength": 0
        }
    }

    try:
        response = requests.post(url, json=data, headers=headers)
        response.raise_for_status()  # Raise an error for HTTP error responses 
        (4xx, 5xx)
        return response.json()  # Return JSON response
    except requests.exceptions.RequestException as e:
        print(f"Error fetching OCR result: {e}")
        return None

# Example usage:
result = fetch_ocr_result()
if result:
    print("OCR Response:", result)