- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在从 Python 生成 HTML 页面。还有使用 pexpect 生成 SSH session 并在同一 Python 代码中获取命令输出的逻辑。但是当我从 Apache httpd 服务器运行 Python 时,它给出了 500 内部服务器错误
。但单独执行Python代码工作正常。
不确定问题是在 Python 还是 Apache 中?
代码如下,我添加了用于调试目的的异常。异常显示
Exception seen in Web page :
Error! pty.fork() failed: out of pty devices name
'child' is not defined name
'child' is not defined name
'child' is not defined name
'child' is not defined name
'child' is not defined name
'child' is not defined name
'child' is not defined name
Code is below #############################################################
import pexpect
import sys
import time
import cgi, cgitb
import getpass
print "Content-Type: text/html\n\n"
try:
child = pexpect.spawn('ssh -t admin@192.***.***.*** login root')
except Exception, e:
print e
try:
child.expect('(?i)password')
except Exception, e:
print e
try:
child.sendline('password')
except Exception, e:
print e
try:
child.expect('(?i)Password:')
except Exception, e:
print e
try:
child.sendline('password')
except Exception, e:
print e
try:
child.expect('-bash# ')
except Exception, e:
print e
try:
child.sendline('ls -al')
except Exception, e:
print e
try:
child.expect('-bash# ')
except Exception, e:
print e
output = child.before
print "Content-Type: text/html\n\n"
print "<html>"
print "<head>"
print "<title>Hello </title>"
print "</head>"
print "<body>"
print "<h1>",output,"</h1>"
print "</body>"
print "</html>"
最佳答案
子变量在第一个 try block 的范围内定义。当它超出第一个 try block 的范围时,解释器就无法识别它。您可以通过将所有 try block 合并为一个来解决此问题。这就足够了。
尝试使用以下代码片段:
#!/usr/bin/env python
import pexpect
import sys
import time
import cgi, cgitb
import getpass
output = ""
try:
child = pexpect.spawn('ssh -t admin@192.***.***.*** login root')
child.expect('(?i)password')
child.sendline('password')
child.expect('(?i)Password:')
child.sendline('password')
child.expect('-bash# ')
child.sendline('ls -al')
child.expect('-bash# ')
output = child.before
except Exception, e:
print e
print "Content-Type: text/html\n\n"
print "<html>"
print "<head>"
print "<title>Hello </title>"
print "</head>"
print "<body>"
print "<h1>",output,"</h1>"
print "</body>"
print "</html>"
关于python - 从 apache httpd 运行 pexpect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22700678/
我正在研究PyroCMS的Docker版本。这是我拥有最新文件的repository。如您所见,我正在运行一个堆栈:CentOS 7(带有Supervisord),MySQL,Apache和PHP。这
为了避免对我本地托管的 apache-tomcat Web 服务器上托管的 Web 应用程序进行点击劫持攻击,我正在尝试编辑“httpd.conf”文件以向其附加 X 选项。 用“sudo nano/
更改 httpd.conf 文件后是否需要重新启动 httpd 才能使更改生效? 最佳答案 是的。 HTTPD.conf 是在 apache 启动时读取的,因此要使任何更改生效,您都需要重新启动它。
我的 CentOS7 服务器上有一个 Laravel 项目,位于文件夹“/var/www/html/myProject”中。 我已将“DocumentRoot”和配置目录中的/etc/httpd/co
我在别人的 linux 服务器上(共享主机)。我没有root访问权限。我已经确定它是一个 Redhat 4.1.2-46,以 Centos Release 5.9(Final) 的形式运行。 我有该站
我需要使用/etc/init.d/httpd status 命令来验证它是否在 shell 中运行。我不想使用 pidof pgrep 等——类似 retval=`/etc/init.d/httpd
我已经下载了 httpd-2.4.16.tar.gz 来自 http://www.apache.org/dist/httpd/ 的包裹 并在我的 ubuntu 14.04 LTS 上提取了两次,但我找
我正在使用免费套餐 Amazon AWS EC2 微型实例并托管一个 Wordpress 网站。由于内存太低,我总是会出现“Error Establishing to Database”之类的常见错误
当我启动我的centOS 服务器时。它通过我的错误如下所示。 启动 httpd: (20)Not a directory: httpd: 无法打开错误日志文件/etc/httpd/logs/error
有谁知道什么会导致 Apache 的错误日志中出现此错误(特别是在 Arch Linux 中): PID file /run/httpd/httpd.pid not readable (yet?) a
我设置了 AWS EC2(Windows Server 2012 R2 Base),允许入站 RDP、HTTP 和 HTTPS,并安装了 Wampserver 以及来自 Microsoft 的 64
当我想在centOS 6.7 上重启httpd 服务时出现以下错误: /etc/init.d/httpd restart Stopping httpd:
x-httpd-php5x 和 application/x-httpd-php5x 有什么区别? 多年来,我一直在使用 application/x-httpd-php 和我的网络托管 (Linux),
我已将 apache httpd 服务器从 2.4.6 升级到 2.4.46。 当我触发 systemctl start httpd 时,它显示以下错误: Starting httpd: /usr/s
我有一个 tomcat,监听 8080 端口,还有一个 apache httpd 监听 80 和 443 端口。 The httpd proxies the client through to tom
我安装了 Centos 7 的新副本。然后我重新启动了 Apache,但 Apache 无法启动。我在这个问题上停留了 3 天。连支持都想不通这个错误。 sudo service httpd star
我最近开始升级我的httpd版本 2.2 从带有 RHEL 4 的旧服务器到附带 httpd 的 RHEL 7 2.4 版。 我注意到的变化之一是 conf.modules.d 包含以下文件的目录:
我在我的linux中使用php7.1: 我可以检查一下: # php -v PHP 7.1.16 (cli) (built: Jun 25 2018 08:12:28) ( ZTS ) 因此在我的 h
我正在使用一个使用 Smarty 模板引擎的框架。它在 Windows 中运行良好,但当我尝试在 LAMP 服务器中运行它时,我收到一条消息,如 SELinux 在您的系统上检测到可疑行为。我附上了整
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我是一名优秀的程序员,十分优秀!