Jump to solution
Verify

The Fix

Upgrade to version 1.0.3 or later.

Based on closed pallets/flask issue #3163 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Jump to Verify Open PR/Commit
@@ -20,6 +20,8 @@ Unreleased - :func:`send_file` supports :class:`~io.BytesIO` partial content. (`#2957`_) +- :func:`open_resource` accepts the "rt" file mode. This still does + the same thing as "r". (:issue:`3163`)
repro.py
from flask import Flask app = Flask(__name__) with app.open_resource('README.md', mode='rt') as f: print(f.read())
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\nUpgrade to version 1.0.3 or later.\nWhen NOT to use: Do not use this fix if compatibility with Python 2 is required.\n\n

Why This Fix Works in Production

  • Trigger: with app.open_resource('README.md', mode='rt') as f:
  • Mechanism: Flask disallows mode='rt' for open_resource() despite it being valid in Python 3
  • Why the fix works: Allows the use of mode='rt' in the open_resource() helper, providing compatibility with Python 3. (first fixed release: 1.0.3).
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • Shows up under Python 3.6 in real deployments (not just unit tests).
  • Flask disallows mode='rt' for open_resource() despite it being valid in Python 3
  • Surfaces as: Traceback (most recent call last):

Proof / Evidence

  • GitHub issue: #3163
  • Fix PR: https://github.com/pallets/flask/pull/3174
  • First fixed release: 1.0.3
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-09
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.59

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“In Python 3, mode='rt' is synonymous with mode='r' but Flask disallows it thinking it is not a valid mode for reading. While this is true in Python 2, Flask could (at least) provide a more meaningful error message, if not just allow it. A s”
Issue thread · issue description · source

Failure Signature (Search String)

  • with app.open_resource('README.md', mode='rt') as f:

Error Message

Stack trace
error.txt
Error Message ------------- Traceback (most recent call last): File "mwe.py", line 5, in <module> with app.open_resource('README.md', mode='rt') as f: File "/home/goodmami/repos/OMW/py3env/lib/python3.6/site-packages/flask/helpers.py", line 1002, in open_resource raise ValueError('Resources can only be opened for reading') ValueError: Resources can only be opened for reading

Minimal Reproduction

repro.py
from flask import Flask app = Flask(__name__) with app.open_resource('README.md', mode='rt') as f: print(f.read())

Environment

  • Python: 3.6

What Broke

Misleading exception raised when attempting to open a resource in text mode.

Why It Broke

Flask disallows mode='rt' for open_resource() despite it being valid in Python 3

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

Upgrade to version 1.0.3 or later.

When NOT to use: Do not use this fix if compatibility with Python 2 is required.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/pallets/flask/pull/3174

First fixed release: 1.0.3

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not use this fix if compatibility with Python 2 is required.

Verify Fix

verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Version Compatibility Table

VersionStatus
1.0.3 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.