File size: 543 Bytes
4416e3b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import os
import dotenv
# Force a clean write of the .env file with the key we found
key = "AIzaSyAKw0taqvQqyFhN5cdz5iAtXj7hfCwdTHE"
with open(".env", "w") as f:
f.write(f"GOOGLE_API_KEY={key}\n")
print("Rewrote .env file.")
# Test loading it
dotenv.load_dotenv(override=True)
loaded_key = os.getenv("GOOGLE_API_KEY")
print(f"Loaded Key: {repr(loaded_key)}")
if loaded_key == key:
print("MATCH! The environment variable is now correct.")
else:
print(f"MISMATCH! Environment variable is: {repr(loaded_key)}")
|