0

I can't get this python command to run on Windows Powershell.

python -c 'import secrets; print("JWT_SECRET_KEY=\"{}\"".format(secrets.token_hex(48)))' >.env
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: 'JWT_SECRET_KEY' is an invalid keyword argument for print()

It works fine when run as two individual lines in the python console.

Python 3.10.0 (tags/v3.10.0:b494f59, Oct  4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import secrets
>>> print("JWT_SECRET_KEY=\"{}\"".format(secrets.token_hex(48)))
JWT_SECRET_KEY="f81fe566fb8b5cd1c7aa6af082dc76fc1b76ab5b15195c00807d6e2a8e656dd2c73ca60cde7f653f38dbaf52a2ed5505"
>>>
2
  • The sad reality up to at least PowerShell 7.2.x is that an extra, manual layer of \-escaping of embedded " characters is required in arguments passed to external programs. This may get fixed in a future version, which may require opt-in. See the linked duplicate for details. Commented Sep 25, 2022 at 12:05
  • 1
    In your case: python -c 'import secrets; print(\"JWT_SECRET_KEY=\\\"{}\\\"\".format(secrets.token_hex(48)))' >.env Commented Sep 25, 2022 at 12:07

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.