SOCKET TIMEOUT ERROR - Zoho Catalyst OCR

SOCKET TIMEOUT ERROR - Zoho Catalyst OCR

Hi guys,

I am getting a "SOCKET TIMEOUT ERROR" when trying to OCR files using Python & Zoho Catalyst OCR

It works for some requests so i know the code works, but when it is a longer scanned pdf for example, it times out.

I would really appreciate your help getting this fixed! The error is: Failed OCR request: {"status":"failure","data":{"message":"Request timed out. Try again","error_code":"SOCKET_TIMEOUT"}}

My code is:

from flask import Flask, request, jsonify
import os
import requests

app = Flask(__name__)

*Auth Token Removed*

@app.route('/')
def index():
    return 'Hello World!'

@app.route('/process_ocr', methods=['POST'])
def process_ocr():
    access_token = get_oauth_token()
    if not access_token:
        return jsonify({'message': 'Failed to authenticate with Zoho OAuth'}), 500

    # Hardcoded image link for testing
    image_link = "*Zoho Workdrive Link removed*?directDownload=true"
   
    # Download the image from the given link
    image_response = requests.get(image_link)
    if image_response.status_code != 200:
        return jsonify({'message': 'Failed to download image', 'status': image_response.status_code}), 500

    # Prepare the OCR API call
    ocr_headers = {
        'Authorization': f'Zoho-oauthtoken {access_token}'
    }
    ocr_files = {
        'image': ('image.pdf', image_response.content, 'application/pdf'),
        'language': (None, 'eng,spa')
    }
    try:
        ocr_response = requests.post(
            headers=ocr_headers,
            files=ocr_files,
            timeout=200  # Set timeout to 60 seconds
        )
    except requests.exceptions.Timeout:
        return jsonify({'message': 'OCR request timed out, please try again later'}), 504

    if ocr_response.status_code != 200:
        print("Failed OCR request:", ocr_response.text)
        return jsonify({'message': 'OCR request failed', 'status': ocr_response.status_code}), 500

    ocr_data = ocr_response.json()
    print("OCR Response:", ocr_data)
    ocr_text = ocr_data.get('data', {}).get('text', '')
   
    # Post the OCR text to the webhook
    webhook_url = '*Webhook URL Removed*'
    webhook_response = requests.post(webhook_url, json={'text': ocr_text})
   
    return jsonify({
        'message': 'OCR processing completed',
        'status': webhook_response.status_code,
        'OCR Text': ocr_text,
        'OCR Data': ocr_data  # Optionally include full OCR response for debugging
    })

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=int(os.getenv('X_ZOHO_CATALYST_LISTEN_PORT', 9000)), debug=True)


    • Topic Participants

    • Lewis

    • Announcements

    • React Nexus 2025 Recap: Catalyst Slate in Action!

      Hey Catalyst Community! We recently attended the React Nexus 2025 conference, an exciting gathering for frontend enthusiasts and React developers. Our team had an incredible time presenting and conducting a hands-on workshop on Catalyst Slate, our streamlined
    • [Webinar] A hands-on guide to Catalyst Stratus

      Have you used Catalyst Stratus yet? It’s an object storage service that makes it easy to handle large files — whether they're coming from your Catalyst app or other Zoho apps. We’re hosting a live coding session where you’ll build a working prototype
    • Catalyst Video Tutorials!

      Hello everyone! We’ve been brewing something exciting behind the scenes, and we’re thrilled to finally share it with you- Catalyst video tutorials are here! We recognized that videos are the predominant medium for learning and discovery these days, so
    • [Webinar] Catalyst Cloud Browser in Action: PDF & Web Rendering Solutions for Regulated Industries

      Hi everyone, Have you ever struggled with rigid PDF tools or clunky rendering logic in BFSI or healthcare apps? Do your clients struggle to deliver compliant, dynamic, and automated documents — and most are still stuck with brittle, server-heavy PDF generation?
    • Announcing Catalyst Developer Bootcamps in India - Zoho Community

      Hey everyone! We're excited to announce a set of developer bootcamps dedicated to Catalyst! These bootcamps are aimed to empower developers to build, scale, and deploy applications with speed and precision, using Catalyst. Whether you're a newcomer or

      Catalyst Community