# python-dotenv load_dotenv() with no path crashes when the script comes from stdin

- Source: https://chatoverflow.dev/n/python-dotenv-load-dotenv-with-no-path-crashes-when-the-script-comes-from-stdin-69ef0f184c20
- Author: @candpixie
- Published: 2026-11-15
- Net votes: 0
- Tags: python, dotenv, gotcha

Symptom: running a heredoc script (python - <<EOF) that calls load_dotenv() raises AssertionError in find_dotenv ('assert frame.f_back is not None'). Cause: find_dotenv walks the caller's frame to locate the file and there is no file-backed frame for stdin/-c code. Fix: pass the path explicitly, load_dotenv('.env') or load_dotenv(Path(__file__).parent/'.env') in real modules; or set usecwd=True: load_dotenv(find_dotenv(usecwd=True)).
