@yoohee
Hello
Thank you for trying Aspose.Cells for Cloud and for sharing the exact error messages.
Below you will find the most common reasons for the 400 (BadRequest) and 405 (MethodNotAllowed) responses you are seeing, together with a step‑by‑step fix that lets the two examples run successfully.
save_spreadsheet_as
– 400 Object reference not set to an instance of an object
Why it happens
SaveSpreadsheetAs
expects all of the following information:
Parameter |
What it is |
Typical cause of the 400 error |
name |
The file name (including extension) that resides in the cloud storage |
The file name is missing, empty, or points to a location that does not exist. |
format |
Target format (pdf , png , …) |
Wrong string case or unsupported format. |
folder |
Cloud folder that contains the source file (optional) |
Not supplied or the folder does not exist. |
storage_name |
Name of the storage (if you use a custom storage) |
Missing when you have more than one storage configured. |
If any of those values are null
the server throws the generic “Object reference not set to an instance of an object.” message you received.
Fix
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.models import SaveSpreadsheetAsRequest
# -------------------------------------------------------------------------
# 1️⃣ Initialise the API client (use your own Client Id / Secret)
# -------------------------------------------------------------------------
api = CellsApi(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
# -------------------------------------------------------------------------
# 2️⃣ Define variables – adjust them to your own cloud storage layout
# -------------------------------------------------------------------------
source_file = "EmployeeSalesSummary.xlsx" # <-- exact name in the cloud
target_format = "pdf"
cloud_folder = "RemoteFolder" # <-- folder that already exists
# (optional) storage_name = "MyStorage" # <-- only if you have multiple storages
# -------------------------------------------------------------------------
# 3️⃣ Call SaveSpreadsheetAs
# -------------------------------------------------------------------------
request = SaveSpreadsheetAsRequest(
name=source_file,
format=target_format,
folder=cloud_folder,
# storage_name=storage_name # uncomment if needed
)
result = api.save_spreadsheet_as(request)
print("Conversion succeeded – PDF saved to:", result.path)
Key points
- The file must already be uploaded to
RemoteFolder
.
You can verify it with api.get_files_list(GetFilesListRequest(folder=cloud_folder))
.
- Use exact case‑sensitive file extension (
.xlsx
).
- The
format
string must be lower‑case (pdf
, png
, …).
If you run the snippet above and still receive 400
, double‑check that the file truly exists in the given folder (you can list the folder contents via the API).
post_convert_workbook
– 405 MethodNotAllowed
Why it happens
ConvertWorkbook
is a POST operation, but the SDK generated request was sent to the wrong URL when any of the following occurs:
Situation |
What went wrong |
How to fix it |
Missing convert_format or typo (e.g., 'Pdf' vs 'pdf' ) |
The server cannot match the route and replies with 405. |
Use lower‑case format names ('pdf' ). |
DataSource points to a non‑existent file |
The request body is accepted, but the service rejects the call because the route resolves to a GET‑only endpoint. |
Ensure data_path points to an existing file (RemoteFolder/EmployeeSalesSummary.xlsx ). |
storage_name omitted while you have a custom storage |
The request is routed to the default storage, which may not contain the file, causing a fallback to a GET endpoint. |
Provide storage_name in DataSource . |
Old SDK version (e.g., 24.x) |
The endpoint signatures changed after version 25.0. |
Upgrade to the latest aspose-cells-cloud Python SDK (≥ 25.8). |
Fix – Full, working example
from asposecellscloud.apis.cells_api import CellsApi
from asposecellscloud.models import (
DataSource,
PdfSaveOptions,
ConvertWorkbookOptions,
PostConvertWorkbookRequest
)
# -------------------------------------------------------------------------
# 1️⃣ Initialise API client
# -------------------------------------------------------------------------
api = CellsApi(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
# -------------------------------------------------------------------------
# 2️⃣ Define source and conversion options
# -------------------------------------------------------------------------
cloud_folder = "RemoteFolder"
source_file = "EmployeeSalesSummary.xlsx"
source_path = f"{cloud_folder}/{source_file}" # <-- full cloud path
data_source = DataSource(
data_source_type="CloudFileSystem",
data_path=source_path,
# storage_name="MyStorage" # uncomment if you use a named storage
)
pdf_options = PdfSaveOptions(
save_format="pdf", # must be lower‑case
one_page_per_sheet=True
)
convert_options = ConvertWorkbookOptions(
data_source=data_source,
convert_format="pdf", # lower‑case!
save_options=pdf_options
)
request = PostConvertWorkbookRequest(
convert_workbook_options=convert_options
)
# -------------------------------------------------------------------------
# 3️⃣ Call the conversion API (POST)
# -------------------------------------------------------------------------
response = api.post_convert_workbook(request)
# The response contains the raw PDF bytes
with open("EmployeeSalesSummary.pdf", "wb") as f:
f.write(response)
print("PDF generated successfully → EmployeeSalesSummary.pdf")
What changed compared with the original snippet
Old code |
New code |
Reason |
convert_format = 'Pdf' |
convert_format = "pdf" |
The service expects a lower‑case format string. |
save_format ='pdf' (inside PdfSaveOptions ) |
save_format = "pdf" |
Same lower‑case rule. |
No explicit storage_name |
(optional) storage_name added if you have a custom storage |
Guarantees the request is routed to the correct storage. |
Using the latest SDK (≥ 25.8) |
— |
Guarantees the endpoint URL matches the current API contract. |
After running the above script you should receive a 200 OK response and a PDF file saved locally.
Helpful Links
Next Steps for You
-
Confirm the file exists in the cloud folder (RemoteFolder
).
from asposecellscloud.apis.storage_api import StorageApi
storage = StorageApi(client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET")
print(storage.get_files_list(GetFilesListRequest(folder="RemoteFolder")))
-
Upgrade to the newest aspose-cells-cloud
package:
pip install --upgrade aspose-cells-cloud
-
Run the fixed examples above. If you still receive an error, please share:
- The exact request JSON printed by
json.dumps(request.to_dict(), indent=2)
(if you add print(request)
).
- The folder structure returned by the storage “list files” call.
With that information we can pinpoint any remaining mismatch.
We’re here to help!
If anything is still unclear, or you hit a different error after applying the fixes, just reply with the additional details and we’ll get it resolved together.
Happy coding with Aspose.Cells Cloud!