Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.
Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Python Cloud Function deploy successfully but doesn't work when triggered by scheduler/pub-sub

Hi,

I'm trying do schedule a cloud function, that worked perfectly when I tested and deployed, but it is giving me an error. The error happens in a specific part, when I'm trying to use pandas df.to_excel:

 
df = client.query(query).to_dataframe() -> Until here, works perfectly
xlsx_file = 'xlsx_file.xlsx'
df = df.to_excel(xlsx_file, index=False') -> Gives me the error:
 
OSError: [Errno 30] Read-only file system: 'excel_file.xlsx'
 
I've tried to change the engine from openpyxl to xlsxwritter, but also failed. What I don't get is that works when testing and deploying but doesn't with scheduler - pub/sub.
 
Thanks
1 1 915
1 REPLY 1

Hi @Vkzera,

Welcome to Google Cloud Community!

Your Cloud Function is encountering a "Read-only file system" error because it lacks permission to write to the designated location. Here are the key steps to resolve it:

1. Choose a writable location:

  • Cloud Storage: Create a Cloud Storage bucket and write the Excel file there using the google-cloud-storage library.
  • Cloud Function's temporary storage: Write to the tmp directory, but remember these files are transient.
  • Alternative formats: Consider using CSV or other supported formats if neither of the above work.

2. Ensure proper environment:

  • Dependencies: Include necessary libraries like Pandas in the deployment package.
  • Permissions: Verify the executing user has write permissions in the chosen directory.

3. Debug and refine:

  • Use detailed logging and Stackdriver reporting to pinpoint the issue.
  • Test locally to replicate the error under similar conditions.
  • Consider file size limits and function timeout constraints.
Top Solution Authors