Skip to main content
Participant
December 3, 2021
Question

ReadTimeoutError multiple time, taking out quota but not returning zip file

  • December 3, 2021
  • 0 replies
  • 303 views

How can I fix this error, been trying to extrac the pdf multiple time with the free trial, it takes the quota but not returning me any zip file.

 

Thanks

raise SdkException("Request could not be completed. Possible cause attached!", sys.exc_info())
adobe.pdfservices.operation.exception.exceptions.SdkException: description =Request could not be completed. Possible cause attached!, requestTrackingId=(<class 'requests.exceptions.ReadTimeout'>, ReadTimeout(ReadTimeoutError("HTTPSConnectionPool(host='cpf-ue1.adobe.io', port=443): Read timed out. (read timeout=4.0)")), <traceback object at 0x0000021C5A19BD40>)

 

My code:

# Copyright 2021 Adobe. All rights reserved.
# This file is licensed to you under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. You may obtain a copy
# of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under
# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
# OF ANY KIND, either express or implied. See the License for the specific language
# governing permissions and limitations under the License.

# NOTE: TRIED (rendition)

import logging
import os.path
import zipfile

from adobe.pdfservices.operation.auth.credentials import Credentials
from adobe.pdfservices.operation.exception.exceptions import ServiceApiException, ServiceUsageException, SdkException
from adobe.pdfservices.operation.pdfops.options.extractpdf.extract_pdf_options import ExtractPDFOptions
from adobe.pdfservices.operation.pdfops.options.extractpdf.extract_element_type import ExtractElementType
from adobe.pdfservices.operation.execution_context import ExecutionContext
from adobe.pdfservices.operation.io.file_ref import FileRef
from adobe.pdfservices.operation.pdfops.extract_pdf_operation import ExtractPDFOperation
from adobe.pdfservices.operation.pdfops.options.extractpdf.extract_renditions_element_type import \
    ExtractRenditionsElementType

logging.basicConfig(level=os.environ.get("LOGLEVEL", "INFO"))

filepath = input("Filepath: ").replace('\\', '/')

output_name = os.path.splitext(filepath)[0].split('/')[-1]

try:
    # Initial setup, create credentials instance.
    credentials = Credentials.service_account_credentials_builder() \
        .from_file("./pdfservices-api-credentials.json") \
        .build()

    # Create an ExecutionContext using credentials and create a new operation instance.
    execution_context = ExecutionContext.create(credentials)
    extract_pdf_operation = ExtractPDFOperation.create_new()

    # Set operation input from a source file.
    source = FileRef.create_from_local_file(filepath)
    extract_pdf_operation.set_input(source)

    # Build ExtractPDF options and set them into the operation
    extract_pdf_options: ExtractPDFOptions = ExtractPDFOptions.builder() \
        .with_elements_to_extract([ExtractElementType.TEXT, ExtractElementType.TABLES]) \
        .with_element_to_extract_renditions(ExtractRenditionsElementType.TABLES) \
        .build()
    extract_pdf_operation.set_options(extract_pdf_options)

    # Execute the operation.
    result: FileRef = extract_pdf_operation.execute(execution_context)

    # Save the result to the specified location.
    output_zip_file = f"./output/{output_name}.zip"
    result.save_as(output_zip_file)

    # Unzip the zip file and store the files into a folder
    output_folder = f"./output/{output_name}"
    if not os.path.exists(output_folder):
        os.mkdir(output_folder)

    zip_ref = zipfile.ZipFile(output_zip_file) # create zipfile object
    zip_ref.extractall(output_folder) # extract file to dir
    zip_ref.close() # close file
    # os.remove(output_zip_file) # delete zipped file

    # return extracted output folder path

except (ServiceApiException, ServiceUsageException, SdkException):
    logging.exception("Exception encountered while executing operation")
    This topic has been closed for replies.