-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Connection string in .env-file not read or parsed properly #496
Comments
Same here, results testing with this # 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/' Simple test code: 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) |
Same problem here as well. |
I tried to reproduce this, but with no luck. Could you confirm the example from https://gist.github.com/Bajron/da5ce70430c0e071bc1b68161a311d6b is enough to replicate the problem in your environments? This is mostly the example from @epomatti. I run it like this
The common denominator so far seems to be the Windows and WSL. |
I am on Windows 10 22H2, tried in If you can get it consistently it would be great if you could debug it a little bit more. My current guesses are:
I have added |
Note the It seems the problem appears in setting the variable in environment or retrieving it back. Added
|
I am afk for some time, could you try the same without the single quotes in cmd. Is it the same for test_env.py? |
Hello everyone! I have a similar situation. I'm testing Azure Cosmos DB locally with the emulator, which provides a "secret" key required for the connection (it's the same for all local installations). The key is I'm working on Windows 11, and the connection to the database had been working correctly, but today I started having problems with my connection. The actual message error was I found this issue and as @Bajron mentioned, it seems like the values are being read correctly, but when accessing them from the variable, in my case, the padding '==' at the end of the key is removed from the value. I tried this and got this results: import dotenv
import os
dotenv.load_dotenv()
print("Loaded value to the environent variable:", os.getenv('COSMOS_KEY'))
print("Value obtained with dotenv_values:", dotenv.dotenv_values().get('COSMOS_KEY')) From VS Code using the virtual environment (as seen on the bottom-right corner): From VS Code using the global Python installation (as seen on the bottom-right corner): Then I ran the test for this issue (https://gist.github.com/Bajron/da5ce70430c0e071bc1b68161a311d6b) directly from PowerShell and got this: I expected it to fail, but apparently it passed the test. Then I tried this: from VS Code, from the global Python installation, I loaded my project's venv and this was the result: In conclusion, I'm confused. Python 3.9.13 |
Same issue: Load creds with When I rename the key from Tried every combination of quotes around the value, but it seems only changing the key will work, albeit temporarily. Issue began for me this last week. Haven't been able to reproduce. Seems to quit parsing correctly at random. tldr; If I change the name of the key, it will work for a few hours before failing again. edit: When switching from
|
@bill-ash could check setting the value directly to os.environ and reading it back? I mean the one that stopped working for you after some time. So far it seems like a faulty handling of environment variables in Python or Windows (parsing in dotenv seems fine). |
Now python-dotenv suddenly started working again for me after getting the Cumulative Update for Windows 11. |
I was also having this problem and in my search I stumbled upon this issue in VS Code that seems to cause the problem for me. |
That's a good point. If VS Code is setting environment variables before the Python program is run, those variables will override what you load with Of course this is different with Then it seems this issue might be unrelated to Python-dotenv? |
With microsoft/vscode#207889, this should now be fixed in VS Code. Would people here be able to try out Visual Studio Code Insiders possibly with a prelease version of the Python extension? |
With the prerelease version of VS code the connection strings are loaded properly again for me. |
Ran into this bug today in VSCode. This is my version:
Running WSL2 Ubuntu 22.04 and connecting VSCode to it. When running my Django project in a Fish terminal the connection string gets picked up correctly. From VSCode it gets corrupted. @DanielRosenwasser With microsoft/vscode#207889 in mind... did this bug just got reintroduced? |
@rwb-truelime no I just unfortunately missed that fish had the same issue (I wasn't familiar with it). Hopefully microsoft/vscode#226980 fixes the issue you're having. |
Thanks @DanielRosenwasser ! |
Hi,
I have an azure blob storage connection string stored in my
.env
file, as follows:Recently I'm experiencing very spotty behavior where me and/or colleagues on similar setups have different results:
Sometimes parsed as
DefaultEndpointsProtocol
sometimes as the full connect string.CONNECT_STRING_BLOB
toCONNECTSTRINGBLOB
, but implementing this change everywhere is not an option, and more importantly it does not always solves the issueNot sure even if this is a python-dotenv issue, but I have litterally no clue anymore where to look as it's so inconsistent and cant seem to find a solution for it.
We have the same requirements file installed, including latest
python-dotenv
.Python 3.8.10
Ubuntu-20.04 on WSL1
working in Visual Studio Code (if that even matters)
The text was updated successfully, but these errors were encountered: