https://prefect.io logo
Title
c

CA Lee

09/19/2020, 11:08 AM
Hi, trying out Prefect cloud, I have a Python script that saves a png file using Matplotlib The method
plt.savefig
takes in a
file_path
arg (below is some sample code):
CWD = os.path.dirname(os.path.abspath(__file__)) # Get CWD
file_path = os.path.join(CWD, "picture.png") # Save in CWD
plt.savefig(file_path)
This all works fine when I am running it on my server using
flow.run()
, however, when it is registered on cloud, invoking a Quick Run results in the error :
PermissionError: [Errno 13] Permission denied: '/picture.png'
The error shows that
file_path
is unable to be parsed to the current working directory that the script is being run from when triggered from Cloud. Would appreciate any insight.. if it helps, I am getting data from Google Sheets, plotting it and sending it to Slack, so I'd like to Prefect this workflow.
I found out the reason - CWD was called when inside a @task decorator. Calling CWD outside the scope of that task works, but can I understand why?
n

nicholas

09/19/2020, 3:48 PM
It sounds like when you're running your flow locally, you're doing so with elevated permission (maybe
sudo
or as a user with access to that file?) but perhaps your agent/executor don't have those same permissions?
c

CA Lee

09/20/2020, 9:57 AM
This doesn't get parsed when called from Prefect cloud ( but gets parsed when run locally via
flow.run()
, from within
@task
):
os.path.dirname(os.path.abspath(__file__))
So the path resolves to just
/'file_name'
. Writing to the root folder
/
is not allowed, hence
PermissionError: [Errno 13]
. The error is resolved when CWD gets called outside of
@task