Multi-line variables not loading correctly with load_env
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
- #570 von @Pritish053 — ohne Merge geschlossen
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 45/100
Rechercherichtung
Reproduce the issue with the shown .env file and Python snippet, then trace the load_env/load_dotenv path and compare it with dotenv_values. Done means quoted multiline variables such as BAZ1 are fully loaded into the environment while the existing escaped-newline behavior remains correct.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
When reading a multi-line environment variable (e.g. an SSH key) only the first line is read when using load_env. dotenv_values appears to read the multiline variable correctly.
Tested on a Apple M2 MacBook Air running Sonoma 14.7.4 with Python 3.12.9. While I had this issue inside a functions-framework function, I was able to reproduce it outside of that environment (see below.)
As an example, try the following .env file:
FOO="foo"
BAR="bar"
BAZ1="baz
baz
baz
baz
baz
"
BAZ2="baz\nbaz\nbaz"
LAST="last"
And the following Python code:
from dotenv import load_dotenv, dotenv_values
import os
load_dotenv()
print(os.environ.get('FOO'))
print(os.environ.get('BAR'))
print(os.environ.get('BAZ1'))
print(len(os.environ.get('BAZ1')))
print(os.environ.get('BAZ2'))
print(len(os.environ.get('BAZ2')))
print(os.environ.get('LAST'))
env = dotenv_values()
print(env)
print(env.get('BAZ1'))
print(len(env.get('BAZ1')))
print(env.get('BAZ2'))
print(len(env.get('BAZ2')))
When I run that code, it produces the following output:
foo
bar
"baz
4
baz
3
last
OrderedDict({'FOO': 'foo', 'BAR': 'bar', 'BAZ1': 'baz\nbaz\nbaz\nbaz\nbaz\n', 'BAZ2': 'baz\nbaz\nbaz', 'LAST': 'last'})
baz
baz
baz
baz
baz
20
baz
baz
baz
11
- Vorherrschende Sprache
- Python
- Sterne
- 8.9k
- Forks
- 600
- Ø Merge
- 4 T. 23 Std.
- Gemergte PRs (30 T.)
- 4
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus theskumar/python-dotenv
-
An empty value ignores ${name:-default}Evtl. vergeben @SashaMIT hat das vor 10 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
theskumar/python-dotenv#715 ·
Maintainer antworten meist innerhalb von 1 Tag
-
set_key and unset_key don't fsync before replacing the .env fileEvtl. vergeben @Imkkey hat das vor 9 Tagen übernommen. Offenenhancement
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
theskumar/python-dotenv#713 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 28/100
theskumar/python-dotenv#693 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
python-dotenv installation without cli masks python-dotenv cliEvtl. vergeben @gyanu2507 hat das vor 49 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
theskumar/python-dotenv#683 · 4 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Feature Request: Automatically copy `default.env` to `.env`Evtl. vergeben @dradetsky hat das vor 158 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
theskumar/python-dotenv#644 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in theskumar/python-dotenv
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 63/100
GAM-team/got-your-back#547 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
UKGovernmentBEIS/inspect_ai#5821 ·
Maintainer antworten meist innerhalb von 1 Tag
-
docs help wanted
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
evidence wanted good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
open-coder-ai/agentseam#195 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag