Skip to content

load_dotenv doesn't parse correctly multiline values when dotenv_path is specified #548

@anton-grigorita

Description

@anton-grigorita

Hi,
I have my .env file that is on the root folder, this file contains 2 variables AUTH_SECRET_KEY and AUTH_PUBLIC_KEY:

AUTH_SECRET_KEY="-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCjzCSceGqoqhu7
...
8lzTleijN6gNpU38Tc87Y6Gr8z92ng==
-----END PRIVATE KEY-----"

AUTH_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAo8wknHhqqKobu/aHq9Pl
...
1VWK3SkMp3DAzxTHnVV2y6ECAwEAAQ==
-----END PUBLIC KEY-----"

In my project im loading this data from the file config.py that is located under ./src/core/config.py
and my .env file is under the project root folder, for that reason im using load_dotenv() specifying the dotenv_path parameter

load_dotenv(dotenv_path=pathlib.Path(__file__).parent.parent / ".env")

after that i print with os.environ

print(os.environ)

and I get that those 2 variables declared in the .env file (which are written in multi lines) are not correctly parsed but only the first line is red

'AUTH_SECRET_KEY': '"-----BEGIN PRIVATE KEY-----', 'AUTH_PUBLIC_KEY': '"-----BEGIN PUBLIC KEY-----'

While if I move the .env file under the same folder of config.py and use only load_dotenv()

load_dotenv()

the vars gets parsed in the correct way.
Is this a bug?
I couldn't find anything on Stackoverflow and not even there on Github.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions