Skip to content

Instantly share code, notes, and snippets.

@Bajron
Last active February 1, 2024 07:11
Show Gist options
  • Save Bajron/da5ce70430c0e071bc1b68161a311d6b to your computer and use it in GitHub Desktop.
Save Bajron/da5ce70430c0e071bc1b68161a311d6b to your computer and use it in GitHub Desktop.
# This fails and I get value "InstrumentationKey".
APPLICATION_INSIGHTS_INSTRUMENTATION_KEY='InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'
# This works and I get the correct full value.
APPLICATION_INSIGHTS_CONNECTION_STRING='InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'

This gist is to test theskumar/python-dotenv#496

See procedures below

Linux (and similar)

python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python test.py

or even

while true; do python test.py; done

Windows (cmd)

python -m venv venv
venv\Scripts\activate.bat
pip install -r requirements.txt
python test.py
python-dotenv==1.0.1
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.environ['APPLICATION_INSIGHTS_INSTRUMENTATION_KEY']
# api_key = os.environ['APPLICATION_INSIGHTS_CONNECTION_STRING']
print(api_key)
assert api_key == 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'
import os
print("get", os.environ.get('APPLICATION_INSIGHTS_INSTRUMENTATION_KEY'))
os.environ['APPLICATION_INSIGHTS_INSTRUMENTATION_KEY'] = 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'
api_key = os.environ['APPLICATION_INSIGHTS_INSTRUMENTATION_KEY']
print("APPLICATION_INSIGHTS_INSTRUMENTATION_KEY is:")
print(api_key)
print()
print("------------------------8<-------------------------")
assert api_key == 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'
import os
from dotenv import load_dotenv, find_dotenv, dotenv_values
print("File is:")
print(open(find_dotenv()).read())
print("Values are:")
print(dotenv_values())
load_dotenv()
api_key = os.environ['APPLICATION_INSIGHTS_INSTRUMENTATION_KEY']
# api_key = os.environ['APPLICATION_INSIGHTS_CONNECTION_STRING']
print("APPLICATION_INSIGHTS_INSTRUMENTATION_KEY is:")
print(api_key)
print()
print("------------------------8<-------------------------")
assert api_key == 'InstrumentationKey=00000000-0000-0000-0000-000000000000;IngestionEndpoint=https://eastus-8.in.applicationinsights.azure.com/;LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment