我正在尝试运行下面的简单片段
port = int(os.getenv('PORT'))
print("Starting app on port %d" % port)
我可以理解PORT是s字符串,但是我需要转换为int。为什么我得到错误
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
我正在尝试运行下面的简单片段
port = int(os.getenv('PORT'))
print("Starting app on port %d" % port)
我可以理解PORT是s字符串,但是我需要转换为int。为什么我得到错误
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
You don't have an environment variable called
PORT
.os.getenv('PORT')
-> returnsNone
-> throws exception when you try to convert it to int在运行脚本之前,请通过以下步骤在终端中创建环境变量:
It is highly likely that, you forgot to
export PORT
. Hence there's no PORT in the env, hence it returnsNone
.