使用特殊字符在 Heroku 中设置环境变量(通过 powershell)

Setting environment variable in Heroku (via powershell) with special characters

Django 1.8、Heroku、Powershell。

我正在尝试在 Heroku 中为我的 django 密钥设置一个环境变量:

(venv) PS WORKFOLDER> heroku config:set SECRET_KEY=eoik6-&dnr9elgmrt7-%3hu_&37hg!9c6x!^khjr3!z*z&b4

我收到此错误消息(3 次 - 因为我在字符串中有 3 个 & 符号):

At line:1 char:77
+ heroku config:set SECRET_KEY=eoik6-&dnr9elgmrt7-%3hu_&37hg!9c6x!^khjr3!z*z&b4
+                                                                             ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed

当我尝试建议的解决方案时(将双引号放在&符号周围):

(venv) PS WORKFOLDER> heroku config:set SECRET_KEY=eoik6-"&"dnr9elgmrt7-%3hu_"&"37hg!9c6x!^khjr3!z*z"&"b4

我收到这个错误:

SECRET_KEY: eoik6-
'dnr9elgmrt7-%3hu_' is not recognized as an internal or external command, operable program or batch file.
'37hg!9c6x!^khjr3!z*z' is not recognized as an internal or external command, operable program or batch file.
'b4' is not recognized as an internal or external command, operable program or batch file.

我也试过用斜杠转义,在整个字符串周围加上引号等。结果相同。那么如何设置我的环境变量呢?

我不熟悉 Heroku,但假设 heroku 是可执行的并且 config:set SECRET_KEY=eo... 是命令行参数,你可以试试这个:

& 'heroku' @('config:set', 'SECRET_KEY=eoik6-"&"dnr9elgmrt7-%3hu_"&"37hg!9c6x!^khjr3!z*z"&"b4')

我只是尝试了一些方法,当你在整个 VALUE 周围加上单引号(在 & 符号周围加上双引号)时它起作用了:

heroku config:set SECRET_KEY='eoik6-"&"dnr9elgmrt7-%3hu_"&"37hg!9c6x!^khjr3!z*z"&"b4'

可通过命令heroku config

验证