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

时间:2022-06-01 20:00:54

Django 1.8, Heroku, Powershell.

Django 1.8,Heroku,Powershell。

I'm trying to set an Environment Variable for my django secret key in Heroku:

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

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

I'm getting this error msg (3 times - since I have 3 ampersands in the string):

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

At line:1 char:77
+ heroku config:set SECRET_KEY=eoik6-&dnr9elgmrt7-%3hu_&37$3hg!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

When I tried the suggested solution (to put double quotes around the ampersands):

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

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

I got this error:

我收到了这个错误:

SECRET_KEY: eoik6-
'dnr9elgmrt7-%3hu_' is not recognized as an internal or external command, operable program or batch file.
'37$3hg!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.

I also tried escaping with slash, putting quotes around the whole string, etc. Same result. So how can I set my environment variable?

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

2 个解决方案

#1


1  

I'm not familiar with Heroku, but assuming that heroku is executable and config:set SECRET_KEY=eo... is a commandline argument, you could try this:

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

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

#2


0  

I just tried a few things and it works when you put single quotes around the whole VALUE (and double quotes around the ampersands):

我只是尝试了一些东西,当你在整个VALUE(以及&符号周围的双引号)上放置单引号时它会起作用:

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

verifiable by the command heroku config

可以通过命令heroku配置验证

#1


1  

I'm not familiar with Heroku, but assuming that heroku is executable and config:set SECRET_KEY=eo... is a commandline argument, you could try this:

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

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

#2


0  

I just tried a few things and it works when you put single quotes around the whole VALUE (and double quotes around the ampersands):

我只是尝试了一些东西,当你在整个VALUE(以及&符号周围的双引号)上放置单引号时它会起作用:

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

verifiable by the command heroku config

可以通过命令heroku配置验证