Sharpless512
Sharpless512

Reputation: 3222

.env file in pipenv (django) - ValueError: embedded null character

I got a .env file inside my project

SECRET_KEY="vvvvvvvtestvvvvv"

I run pipenv shell

But I get like a bunch of errors.

PS S:\github\fozvi> pipenv shell
Loading .env environment variables…
Traceback (most recent call last):
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Sander-PC\AppData\Local\Programs\Python\Python37\Scripts\pipenv.exe\__main__.py", line 9, in <module>
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\cli\command.py", line 381, in shell
    load_dot_env()
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\core.py", line 172, in load_dot_env
    dotenv.load_dotenv(dotenv_file, override=True)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\dotenv\main.py", line 262, in load_dotenv
    return DotEnv(f, verbose=verbose).set_as_environment_variables(override=override)
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\site-packages\pipenv\vendor\dotenv\main.py", line 105, in set_as_environment_variables
    os.environ[k] = v
  File "c:\users\sander-pc\appdata\local\programs\python\python37\lib\os.py", line 684, in __setitem__
    self.putenv(key, value)
ValueError: embedded null character

What am I doing wrong?

Upvotes: 2

Views: 894

Answers (2)

Igor Z
Igor Z

Reputation: 31

Just ran into this problem. It may be a file encoding issue.

Try opening the .env file in Notepad++, change the encoding to UTF-8, then save the file and try again.

Upvotes: 3

ThiefMaster
ThiefMaster

Reputation: 318518

Probably your SECRET_KEY contains a \0 somewhere and you can't have NUL bytes in an environment variable. Just remove it from your SECRET_KEY in the env file and it should work.

Upvotes: 0

Related Questions