3 months ago
My app crashed after deployed, so do I. For one day and one night I sat before the screen try again and again but never solved. The app cant access variables.
two variables ZP_API_KEY and api_key had been built.
using "os.environ.get('ZP_API_KEY')" get None, either api_key.
using "logger.info('Show all Variables: %s', {k: '***' if 'KEY' in k else v for k, v in os.environ.items()})", only Railway provided variables presented.
I have deployed many times. search the Doc and asked AI agents ,haven't solved.
Please help me! Thanks!
11 Replies
3 months ago
Your app can't access custom env vars because they aren't set in Railway's Environment tab. Go to Railway → Project → Variables → add ZP_API_KEY
, then redeploy. .env
files don’t work in production. Let me know if you need help with fallback logging.
memamun
Your app can't access custom env vars because they aren't set in Railway's Environment tab. Go to Railway → Project → Variables → add ZP_API_KEY, then redeploy. .env files don’t work in production. Let me know if you need help with fallback logging.
3 months ago
Thanks for your reply.
1.RAILWAY_PROJECT_ID:ea4ca8cc-1ad1-4ad3-961d-4cdf0606c8f7
2.Here is the Deploy logs:
ou reached the start of the range → May 31, 2025 2:48 PM
May 31 14:49:17
Starting Container
May 31 14:50:54
2025-05-31 06:49:17,744 - SecureImageProxy - INFO - Server environment, loading environment variables from Railway
May 31 14:50:54
2025-05-31 06:49:17,745 - SecureImageProxy - INFO - RAILWAY_PROJECT_ID: ea4ca8cc-1ad1-4ad3-961d-4cdf0606c8f7
May 31 14:50:54
2025-05-31 06:49:17,745 - SecureImageProxy - INFO - All environment variables: {'RAILWAY_BETA_ENABLE_RUNTIME_V2': '1', 'RAILWAY_GIT_BRANCH': 'main', 'PYTHONUNBUFFERED': '1', 'RAILWAY_SNAPSHOT_ID': '59f39d55-9963-4ea3-9500-a36274ec0cb2', 'NIXPKGS_ALLOW_UNFREE': '1', 'HOSTNAME': '53826efec3e1', 'PYTHONHASHSEED': 'random', 'NIXPKGS_ALLOW_BROKEN': '1', 'RAILWAY_PROJECT_NAME': 'zoological-magic', 'NIXPACKS_PATH': '/opt/venv/bin:', '__ETC_PROFILE_NIX_SOURCED': '1', 'ENV': '/etc/profile', 'PWD': '/app', 'NIX_PROFILES': '/nix/var/nix/profiles/default /root/.nix-profile', 'RAILWAY_REPLICA_ID': '2711b5dc-d052-4830-8b18-ed2771bde846', 'RAILWAY_GIT_COMMIT_SHA': '6960ccb99ff805ed243b32034859cf939cc8725b', 'PORT': '8080', 'NIX_PATH': '/nix/var/nix/profiles/per-user/root/channels', 'RAILWAY_GIT_COMMIT_MESSAGE': '全英版试试', 'RAILWAY_ENVIRONMENT_NAME': 'production', 'container': 'podman', 'HOME': '/root', 'RAILWAY_GIT_REPO_OWNER': 'Dragontxl', 'GIT_SSL_CAINFO': '/etc/ssl/certs/ca-certificates.crt', 'NIX_SSL_CERT_FILE': '/etc/ssl/certs/ca-certificates.crt', 'RAILWAY_GIT_REPO_NAME': 'ttp', 'RAILWAY_PRIVATE_DOMAIN': 'ttp.railway.internal', 'RAILWAY_PROJECT_ID': 'ea4ca8cc-1ad1-4ad3-961d-4cdf0606c8f7', 'PIP_DEFAULT_TIMEOUT': '100', 'NIXPACKS_METADATA': 'python', 'BUILDKIT_DOCKERFILE_CHECK': 'skip=all', 'RAILWAY_GIT_AUTHOR': 'Dragontxl', 'USER': 'root', 'PIP_DISABLE_PIP_VERSION_CHECK': '1', 'LIBRARY_PATH': '~/.nix-profile/lib:', 'RAILWAY_DEPLOYMENT_ID': 'adc363a2-c681-4fc7-b3e4-9091928ff3da', 'PYTHONFAULTHANDLER': '1', 'RAILWAY_SERVICE_NAME': 'ttp', 'SHLVL': '0', 'NIXPKGS_ALLOW_INSECURE': '1', 'RAILWAY_ENVIRONMENT': 'production', 'PYTHONDONTWRITEBYTECODE': '1', 'RAILWAY_SERVICE_ID': '80452941-df1e-42cd-a151-9f854882c1e9', 'LD_LIBRARY_PATH': '/nix/store/s94fwp43xhzkvw8l8nqslskib99yifzi-gcc-13.3.0-lib/lib:/nix/store/ncjma3lhr1sf6mqaczl9mfhjmp6ix58w-zlib-1.3.1/lib:/usr/lib', 'QTDIR': '~/.nix-profile:', 'RAILWAY_ENVIRONMENT_ID': '8beaf82c-ec23-4f12-a13d-0a31f7d5b509', 'XDG_DATA_DIRS': '/usr/local/share:/usr/share:/root/.nix-profile/share:/nix/var/nix/profiles/default/share:/root/.nix-profile/share:/nix/var/nix/profiles/default/share', 'PATH': '/opt/venv/bin:/opt/venv/bin::/root/.nix-profile/bin:/root/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/bin:/sbin:/usr/bin:/usr/sbin', 'RAILWAY_REPLICA_REGION': 'asia-southeast1-eqsg3a', 'PIP_NO_CACHE_DIR': '1', 'CPATH': '~/.nix-profile/include:', '_': '/opt/venv/bin/python', 'LC_CTYPE': 'C.UTF-8'}
May 31 14:50:54
2025-05-31 06:49:17,745 - SecureImageProxy - ERROR - Zhipu API key not set! Please configure ZP_API_KEY in Railway environment variables
May 31 14:50:54
Traceback (most recent call last):
May 31 14:50:54
File "/app/main.py", line 786, in <module>
May 31 14:50:54
raise RuntimeError('Zhipu API key not configured')
May 31 14:50:54
RuntimeError: Zhipu API key not configured
codes in if__name__==main:
if __name__ == '__main__': # Initialize logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger('SecureImageProxy') # Load environment variables if not os.environ.get('RAILWAY_PROJECT_ID'): load_dotenv() logger.info('Non-server environment, loading environment variables from local .env file') else: logger.info('Server environment, loading environment variables from Railway') logger.info('RAILWAY_PROJECT_ID: %s', os.environ.get('RAILWAY_PROJECT_ID')) logger.info('All environment variables: %s', {k: '***' if 'KEY' in k else v for k, v in os.environ.items()}) # Check ZP_API_KEY api_key = os.environ.get('ZP_API_KEY') if not api_key: logger.error('Zhipu API key not set! Please configure ZP_API_KEY in Railway environment variables') raise RuntimeError('Zhipu API key not configured') 4. you can find shotcut for Variables in attached. Looking forward to your reply. Many Thanks.
Attachments
3 months ago
open your railway canvas
Click on the service that has the code
Go to the “variables” tab
Send a screenshot
If it helps:
打开你的 Railway 画布
点击包含代码的服务
进入 “variables(变量)” 标签页
发送截图
angobello
open your railway canvasClick on the service that has the codeGo to the “variables” tabSend a screenshotIf it helps:打开你的 Railway 画布点击包含代码的服务进入 “variables(变量)” 标签页发送截图
3 months ago
Sorry , but I cant find canvas button. 找不到canvas 按钮。
memamun
Your app can't access custom env vars because they aren't set in Railway's Environment tab. Go to Railway → Project → Variables → add ZP_API_KEY, then redeploy. .env files don’t work in production. Let me know if you need help with fallback logging.
3 months ago
I have del and add for many times. thanks all the same.
dragontxl
I have del and add for many times. thanks all the same.
3 months ago
Can you share a screenshot if possible
angobello
Can you share a screenshot if possible
3 months ago
Is this one OK? thanks.
Attachments
angobello
Yes, click on "Deploy"Then wait for the redeploy and try again
3 months ago
OK ,done what's next?
Attachments
angobello
Click on "Deploy"
3 months ago
it does work! Thanks for your help!!
Status changed to Open chandrika • 4 months ago
Status changed to Solved chandrika • 4 months ago