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"
>>>
tomtomnz
  • 187
  • 14
  • 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. – mklement0 Sep 25 '22 at 12:05
  • In your case: ``python -c 'import secrets; print(\"JWT_SECRET_KEY=\\\"{}\\\"\".format(secrets.token_hex(48)))' >.env`` – mklement0 Sep 25 '22 at 12:07

0 Answers0