examples icon indicating copy to clipboard operation
examples copied to clipboard

Permission Denied for Accessing Flask Caching

Open eden-chan opened this issue 3 years ago • 2 comments

I'm using a flask app starter code, and I'm running into this caching permission issue from vercel dashboard runtime logs when deployed on vercel with vercel ⁠—prod, but don't run into the issue when testing locally with vercel dev.

Is this a caching permission issue with edge functions?

[WARNING]	2023-03-27T04:17:56.207Z	d820d1ac-8e93-4d09-a5a0-7f97292c013e	Exception raised while handling cache file '/var/task/cache/2029240f6d1128be89ddc32729463129'
Traceback (most recent call last):
  File "/var/task/cachelib/file.py", line 209, in get
    with self._safe_stream_open(filename, "rb") as f:
  File "/var/lang/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/var/task/cachelib/file.py", line 330, in _safe_stream_open
    fs = self._run_safely(open, path, mode)
  File "/var/task/cachelib/file.py", line 324, in _run_safely
    output = fn(*args, **kwargs)
PermissionError: [Errno 13] Permission denied: '/var/task/cache/2029240f6d1128be89ddc32729463129'[WARNING]	2023-03-27T04:17:56.208Z	d820d1ac-8e93-4d09-a5a0-7f97292c013e	Exception raised while handling cache file '/var/task/cache/2029240f6d1128be89ddc32729463129'
Traceback (most recent call last):
  File "/var/task/cachelib/file.py", line 209, in get
    with self._safe_stream_open(filename, "rb") as f:
  File "/var/lang/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/var/task/cachelib/file.py", line 330, in _safe_stream_open
    fs = self._run_safely(open, path, mode)
  File "/var/task/cachelib/file.py", line 324, in _run_safely
    output = fn(*args, **kwargs)
PermissionError: [Errno 13] Permission denied: '/var/task/cache/2029240f6d1128be89ddc32729463129'[WARNING]	2023-03-27T04:17:56.208Z	d820d1ac-8e93-4d09-a5a0-7f97292c013e	Exception raised while handling cache file '/var/task/cache/85cd70373cda23597cde41f6a0be4bed'
Traceback (most recent call last):
  File "/var/task/cachelib/file.py", line 248, in set
    fd, tmp = tempfile.mkstemp(
  File "/var/lang/lib/python3.9/tempfile.py", line 336, in mkstemp
    return _mkstemp_inner(dir, prefix, suffix, flags, output_type)
  File "/var/lang/lib/python3.9/tempfile.py", line 255, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
OSError: [Errno 30] Read-only file system: '/var/task/cache/tmpc8_tjfew.__wz_cache'

eden-chan avatar Mar 27 '23 04:03 eden-chan

I am also having this issue.

rajmethi avatar Feb 18 '24 03:02 rajmethi

I think that I have a similar error, i use a decorator to fetch data from the registered user session:

link to repo

def login_required(f):
    """
    Decorate routes to require login.

    http://flask.pocoo.org/docs/0.12/patterns/viewdecorators/
    """

    @wraps(f)
    def decorated_function(*args, **kwargs):
        if session.get("user_id") is None:
            return redirect("/login")
        return f(*args, **kwargs)

    return decorated_function

# ------ # 

@app.route("/portifolio")
@login_required
def portifolio():
    """This function is used to display the user's portfolio of stocks.

    It retrieves information about the stocks the user holds from the database and calculates the
    total value of each stock (``shares`` * ``price``) and the total value of the entire portfolio
    (sum of individual stock values + ``cash``).

    The function returns the rendered ``portfolio.html`` template, passing the necessary data to be
    displayed in the table.
    """
    # ...

    return render_template("portifolio.html", rows=data, cash=cash, total_value=current)

I get a 302 on this route and redirects to / with this warning:

APR 06 11:40:13.26 200 GET /login
[WARNING] (see next snippet)
APR 06 11:40:13.11 302 GET /portifolio
[WARNING]	2024-04-06T10:40:13.218Z	5dfc054b-479a-4ef3-9433-6bb886331452	Exception raised while handling cache file
Traceback (most recent call last):
  File "/var/task/cachelib/file.py", line 271, in delete
    os.remove(self._get_filename(key))
OSError: [Errno 30] Read-only file system: '/var/task/flask_session/6d898c758089f3b24c52707fc7aa1cb5'

see7e avatar Apr 06 '24 10:04 see7e