Skip to content

8.3.0 Regression: Unhandled OSError running under Apache2/mod_wsgi  #5583

@leon-matthews

Description

@leon-matthews

What did you do?

After upgrading one of our Django projects to Pillow 8.3.0 we got a 500 error when trying to create a thumbnail on any page. Downgrading to Pillow 8.2.0 resolved (worked around) the error.

What did you expect to happen?

Image resizing to continue as normal.

What actually happened?

A 500 error and a long backtrace in the logs:

Internal Server Error: /case-studies/chronic-pelvic-pain/
Traceback (most recent call last):
    ...
    File "...lib/python3.8/site-packages/PIL/ImageFile.py", line 496, in _save
        if fp == sys.stdout or (hasattr(sys.stdout, "buffer") and fp == sys.stdout.buffer):
    OSError: sys.stdout access restricted by mod_wsgi

What are your OS, Python and Pillow versions?

  • OS: Ubuntu 20.04.2 LTS (Linux 5.8.0-1038-aws)
  • Python: Python 3.8.10
  • Django 3.2.5
  • Pillow: 8.3.0 (in a venv)
  • Apache (v2.4.41) / mod_wsgi (v4.6.8)

My guess

The default settings for mod_wsgi restrict access to sys.stdout.

In the interests of promoting portability of WSGI applications, mod_wsgi restricts
access to sys.stdout and will raise an exception if an attempt is made to use sys.stdout explicitly.

Recent commit 0f68e63 accesses sys.stdout explicitly in line 496 of PIL/ImageFile.py, as per the traceback above.

Thanks

Thank you for looking into this. Please let me know how I can help with testing - or anything else that might be required.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions