我目前正在设置一个网络服务器,仅供个人和测试使用。现在我正在尝试运行一些Python应用程序,但是当我启动它们时,它们在127.0.0.1:5000上运行。我是否可以转发此内容以使其可以在其他地方访问?
我在 GCE 的 VM 上运行一个非常简单的 http 服务器。
代码非常简单
from flask import Flask, render_template, request, json, abort
app = Flask(__name__)
@app.route('/', methods=['GET'])
def heartbeat():
return 'hello'
if __name__ == '__main__':
app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
我可以使用lynx本地访问服务器上的“/”
我没有修改任何防火墙规则。以下是部分规则:
这是与网络相关的 VM 信息的一部分
你可以看到http交通是允许的。
但是,当我尝试从我的 PC 连接到服务器时,连接 t
我需要在 Windows 上安装 Python 3.6.x,作为无需用户交互的自动化过程的一部分。最近 Python 版本提供了使用“msiexec”实用程序进行安装的 MSI 文件,但是没有更多可用于 Python 3.6.X 的 MSI 版本文件。有没有其他选择?
CMD我的 dockerfile 是这样的:["python", "myproject/start_slide_server.py"]
但是,为了使其工作,我需要将其设置PYTHONPATH为/app,它是myproject
如果我启动 docker 进程并覆盖CMD,bash我可以运行以下命令
root@42e8998a8ff7:/app# export PYTHONPATH=.
root@42e8998a8ff7:/app# python myproject/start_slide_server.py
* Running on http://0.0.0.0:8090/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 236-035-556
Run Code Online (Sandbox Code Playgroud)
它按预期工作
现在我添加一行
RUN export PYTHONPATH=/app
Run Code Online (Sandbox Code Playgroud)
前
CMD ["python" , "myproject/start_slide_server.py"]
Run Code Online (Sandbox Code Playgroud)
它刚刚失败了
Traceback (most recent call last):
File "/app/myproject/start_slide_server.py", line 23, in <module>
from myproject import env
ImportError: No module named myproject
Run Code Online (Sandbox Code Playgroud)
看起来这RUN条线根本没有任何影响
我真的不想 …
我正在尝试virtualenv以编程方式管理 Jenkins 服务器上每个作业的 Python 环境,通过共享库扩展实现,以根据每个作业激活环境。例如:
/vars/activateEnvironment.groovy:
def call(String env = "/usr/local/etc/environments/jenkins-$JOB_NAME") {
sh """
mkdir ${env}
virtualenv ${env}
source ${env}/bin/activate
"""
}
Run Code Online (Sandbox Code Playgroud)
管道脚本,其中virtualenv-scripts存储库包含上述文件:
@Library('virtualenv-scripts') _
pipeline {
agent any
stages {
stage("Test") {
steps {
activateEnvironment()
sh 'which pip'
sh 'echo \$PATH'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
运行此管道脚本,我得到以下输出:
[Pipeline] sh
[example-pipeline] Running shell script
+ echo /sbin:/usr/sbin:/bin:/usr/bin
/sbin:/usr/sbin:/bin:/usr/bin
[Pipeline] sh
[example-pipeline] Running shell script
+ which pip
/bin/pip
Run Code Online (Sandbox Code Playgroud)
我尝试使用此答案使 Jenkins 使用登录 shell,但这仍然会在每次 …
我正在尝试将我的项目移至 docker,并且我一直在使用 alpine 变体。这是一个带有 postgres 数据库的 django 项目
这是我安装依赖项的方法:
...
ADD ./requirements.txt /srv/sites/mysite/requirements.txt
RUN echo "http://mirror.leaseweb.com/alpine/edge/testing" >>
/etc/apk/repositories
RUN apk add --no-cache --virtual .build-deps \
build-base postgresql-dev libffi-dev gcc libc-dev linux-headers bash \
geos geos-dev jpeg-dev zlib-dev \
&& pip install -r requirements.txt \
&& find /usr/local \
\( -type d -a -name test -o -name tests \) \
-o \( -type f -a -name '*.pyc' -o -name '*.pyo' \) \
-exec rm -rf '{}' + \
&& runDeps="$( \ …Run Code Online (Sandbox Code Playgroud) 我在 Python3 和 Enterprise Linux 8 (Rocky Linux 8) 之上使用 Ansible。
当我尝试使用 时json_query,出现以下错误:
fatal: [ansible]: FAILED! => {"msg": "You need to install \"jmespath\" prior to running json_query filter"}
Run Code Online (Sandbox Code Playgroud)
但 Python 模块似乎已经安装:
# dnf install python3-jmespath
Last metadata expiration check: 1:44:38 ago on Mi 02 Nov 2022 12:54:28 CET.
Package python3-jmespath-0.9.0-11.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
# pip3 install jmespath
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Ubuntu 上使用 shebang 运行 Python 脚本。当我创建一个 python 脚本时
#! /usr/bin/env python
import sys
Run Code Online (Sandbox Code Playgroud)
...并运行它我得到一个shell错误:
root@host:/home/user# ./test.py
: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我怎样才能让它工作?
解决方案:使用 dos2unix 从行尾中删除 '\r's。
我的 gameServer.py 脚本通过 PuTTy 远程运行。
gameServer.py 看起来像这样:
而真: ((监听数据包)) ((将所有数据包发送给所有客户端))
当我正常执行脚本时:
./gameServer.py
它工作正常,但终端被捆绑。自然退出 PuTTy 会终止我的脚本。
我希望能够关闭 PuTTY 并让这个脚本永久运行,所以我尝试了:
./gameServer.py &
但这实际上不起作用,我不明白为什么。首先,它在该&模式下运行时不接收或发送任何数据包,其次,每当我在控制台中键入 enter 或 ANYTHING 时,它都会“+停止”。
import os, sys, time
servers = ['dev','admin','db1']
for s in servers:
cmd = 'scp /etc/hosts regular_user@%s:/etc/hosts' % s
print cmd
os.system(cmd)
Run Code Online (Sandbox Code Playgroud)
我编写了这个脚本来将我当前的 HOSTS 文件复制到我所有的其他服务器。但是,我想从普通用户而不是 ROOT 执行此操作。
由于覆盖 /etc/hosts 需要 root 特权,我想做SUDO。如何将 sudo 放入该脚本中?
这将不起作用,因为更改 /etc/hosts 文件的权限被拒绝。
cmd = 'sudo scp /etc/hosts regular_user@%s:/etc/hosts' % s
Run Code Online (Sandbox Code Playgroud)