Python REST API to Process PDF in Cloud BROKEN

First off, according to the README.md on Github:

	# Get your ClientId and ClientSecret from https://dashboard.aspose.cloud (free registration required).
	pdf_api_client = asposepdfcloud.ApiClient('MY_CLIENT_ID', 'MY_CLIENT_SECRET')
	pdf_api = asposepdfcloud.PdfApi(pdf_api_client)
	file_name = 'PdfWithAnnotations.pdf'
	page_number = 2
	response = pdf_api.get_page_annotations(file_name, page_number, folder=temp_folder)

This example, which is crucial to start using the Python REST API doesn’t work, it’ll simply give you an error.

asposepdfcloud.rest.ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 20 Mar 2021 22:05:00 GMT', 'Content-Type': 'application/json; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Set-Cookie': 'AWSALB=GEPeXFXylmkX26v1qIjS7hP9twmsQm6aYh0INhQ4x8rCSmtPTfdUILgfMq+QPyqQlXgznQ9VvLp1f/LcBCUlXncp1UYUY8G/C4uXNCjCnFlgmKh3mcbz4QvrSTJI; Expires=Sat, 27 Mar 2021 22:05:00 GMT; Path=/, AWSALBCORS=GEPeXFXylmkX26v1qIjS7hP9twmsQm6aYh0INhQ4x8rCSmtPTfdUILgfMq+QPyqQlXgznQ9VvLp1f/LcBCUlXncp1UYUY8G/C4uXNCjCnFlgmKh3mcbz4QvrSTJI; Expires=Sat, 27 Mar 2021 22:05:00 GMT; Path=/; SameSite=None; Secure, .Prj.Customer=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/; samesite=lax, .Prj.Customer=1c681fac-b5ae-4078-bede-29c25d3578dc; expires=Sun, 20 Mar 2022 22:05:00 GMT; path=/; samesite=lax; httponly', 'Cache-Control': 'no-store, no-cache, max-age=0', 'Pragma': 'no-cache'})
HTTP response body: {"error":"invalid_client"}

Now, the issue is that Aspose made a mistake, whereby it’s reading the client_id as client_secret, and opposite. The quick workaround is to just swap the variables around.

This was brought to their attention on Mar 20, 2021, it’s now more than 3 years later and it’s still not fixed.

  • EDIT: Everything below this line was caused by user error and is NOT an issue!

Then you continue, now you want to do a simple operation like replacing some text.

Then you get this error:

asposepdfcloud.rest.ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Date': 'Thu, 30 May 2024 17:13:35 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive'})
HTTP response body: {"RequestId":"a519229f001f8c7502f46b66558e9886","Error":{"Code":"errorAmazonS3Storage","Message":"AmazonS3 Storage exception: The specified key does not exist. Bucket 'aspose.cloud-filestorage-prod', FilePath '1000164/ada7fd05-e1cb-41d0-aef2-19102f2a1c65/*redacted*.pdf'","Description":"Operation Failed. The remote server returned an error: (404) Not Found.","DateTime":"2024-05-30T17:13:35.0063916Z","InnerError":null}}

Using their own tests, we get this error. Why include tests if they are never ran/evaluated?

What is going on? Can someone make the damn SDK usable?

Does nobody use this piece of software? Can someone advise me how to get around these hurdles?

oleg.subachev shot in the dark here, I believe you’re the man who can fix this. Let me know, any help is appreciated greatly in advance!

Sorry for that. We created an internal work WORDSCLOUD-2731 to discuss / fix the issue.

1 Like

@klaudiusz419
How exactly do you perform text replacing ?
Our Text Replace Tests (see testPostDocumentTextReplace and testPostPageTextReplaceByRect) run OK.

oleg.subachev

import os
import asposepdfcloud
from asposepdfcloud.apis.pdf_api import PdfApi
from asposepdfcloud.models import TextReplace, TextReplaceListRequest

client_id = '**redacted**'
client_secret = '**redacted**'

pdf_api_client = asposepdfcloud.ApiClient(client_secret, client_id)
pdf_api = asposepdfcloud.PdfApi(pdf_api_client)

os.chdir('pdfs')
file_name = '**redacted**'
page_number = 1
text_replace = TextReplace(old_value="test", new_value="1234", regex=False)
text_replace_list = TextReplaceListRequest(text_replaces=[text_replace])
response = pdf_api.post_document_text_replace(file_name, text_replace_list)
asposepdfcloud.rest.ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 03 Jun 2024 15:26:24 GMT', 'Content-Type': 'application/json; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive'})
HTTP response body: {"RequestId":"8724b65a0be849b6d3111df8fa9990ca","Error":{"Code":"errorAmazonS3Storage","Message":"AmazonS3 Storage exception: The specified key does not exist. Bucket 'aspose.cloud-filestorage-prod', FilePath '1000164/ada7fd05-e1cb-41d0-aef2-19102f2a1c65/**redacted**.pdf'","Description":"Operation Failed. The remote server returned an error: (404) Not Found.","DateTime":"2024-06-03T15:26:24.8183916Z","InnerError":null}}

After adding the missing line regarding the uploadFile, it now works. Somehow I missed that part when I were copying code over from the tests. I apologise for not seeing that, now my only valid complaint is the client_id and client_secret parameters being swapped around.

Edit: Works fucking amazing now!

@klaudiusz419
OK.
I have swapped client_id and client_secret parameters.

1 Like