Free Support Forum - aspose.cloud

Python convert DOCX to PDF using Aspose.Words REST API throws NameError

I am getting an error like this “NameError: name ‘WordsApi’ is not defined”.I am using Python.

@Sai95

Please double check that you have installed the Aspose.Words Cloud SDK for Python package from PIP. It is working fine at my end. Please check the sample working code for reference.

# For complete examples and data files, please go to https://github.com/aspose-words-cloud/aspose-words-cloud-python
# Import module
import asposewordscloud
import asposewordscloud.models.requests
from shutil import copyfile

# Please get your Client ID and Secret from https://dashboard.aspose.cloud.
client_id='xxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx'
client_secret='xxxxxxxxxxxxxxxxxxxxxxxxxxx'

words_api = asposewordscloud.WordsApi(client_id,client_secret)
words_api.api_client.configuration.host='https://api.aspose.cloud'

filename = 'C:/Temp/02_pages.docx'
dest_name = 'C:/Temp/02_pages.pdf'
#Convert Docx to PDF
request = asposewordscloud.models.requests.ConvertDocumentRequest(document=open(filename, 'rb'), format='pdf')
result = words_api.convert_document(request)
copyfile(result, dest_name)