[Python] python .env inconsistent result

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    .env

    ENDPOINT="http://localhost:9000"


    py file

    import os
    from urllib.parse import unquote
    from dotenv import load_dotenv

    load_dotenv()


    endpoint = os.getenv("ENDPOINT", "")
    print(endpoint)
    # OR
    endpoint = unquote(os.getenv("ENDPOINT", ""))
    print(endpoint)


    both prints http\x3a//localhost\x3a9000

    If I add a new .env entry

    NEW_ENDPOINT="http://localhost:9001"


    and print as

    endpoint = os.getenv("NEW_ENDPOINT", "")
    print(endpoint)


    will return as http://localhost:9001

    However, if I restart my .venv, it will return as http\x3a//localhost\x3a9001

    Continue reading...

Compartilhe esta Página