[英]How to join endpoint with IP adress from environmental variables, in Python
I'm trying to get the Kubernetes service IP using env variable to an endpoint inside a python app.我正在尝试使用 env 变量将 Kubernetes 服务 IP 获取到 python 应用程序内的端点。
For example in NodeJs:例如在 NodeJs 中:
(`http://${process.env.AUTH_ADDRESS}/hashed-password/` + password);
using backticks and ${}
IP address is fetched from the env variable使用反引号和
${}
IP 地址是从 env 变量中获取的
In Python I tried在 Python 中我试过了
opc.tcp://"+str(os.environ.get('USER_SERVICE_SERVICE_HOST'))+":4840/
but the result is actually something like ('10.98.191.127', 4840).但结果实际上类似于 ('10.98.191.127', 4840)。 I need it in a format like '10.98.191.127:4840' I have tried concatenate strings individually
我需要像 '10.98.191.127:4840' 这样的格式我已经尝试过单独连接字符串
Try to convert the port 4840
to str
type.尝试将端口
4840
转换为str
类型。 Something like:就像是:
str(os.environ.get('USER_SERVICE_SERVICE_HOST'))+":"+str(4840)
Something I would do is to use f-string format, something like:我会做的是使用 f-string 格式,例如:
f"{os.environ.get('USER_SERVICE_SERVICE_HOST')}:4840"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.