我有一个python代码
import paramiko
import time
import sys
import os
import pdb
ip = "1.1.1.1"
un = "root"
pw = "123"
key_filename='/path/to/id_rsa'
def ssh_con (ip, un, pw):
global ssh
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=un, password=pw, key_filename=key_filename)
def cmd_io (command):
global ssh_cmd
ssh_cmd.send("%s \n" %command)
time.sleep(1)
output = ssh_cmd.recv(10000).decode("utf-8")
print (output)
ssh_con(ip,un,pw)
ssh_cmd = ssh.invoke_shell()
cmd_io("clientsim cli")
time.sleep(2)
cmd_io("stop subscriber-group dth-sub stop-traffic udp")
time.sleep(1)
cmd_io("stop subscriber-group dth-sub")
time.sleep(1)
cmd_io("q")
cmd_io("exit")
我试图通过PHP运行它
我已经尝试了
$command = "python ".public_path().'/python/start_clientsim.py 2>&1';
$result = shell_exec($command);
我一直在
回溯(最近一次调用最后一次):↵文件" /Applications/MAMP/htdocs/code/site/portal/public/python/stop_clientsim.py",第32行,位于↵cmd_io(&# 34; clientsim cli")↵文件" /Applications/MAMP/htdocs/code/site/portal/public/python/stop_clientsim.py",第28行,cmd_io↵打印(输出)↵UnicodeEncodeError :' ascii'编解码器不能对位于360-362位置的字符进行编码:序数不在范围内(128)↵
但如果我跑
python /Applications/MAMP/htdocs/code/site/portal/public/python/stop_clientsim.py 2>&1
直接在我的终端上,它完全正常。
我在这里做错了什么?
如何进一步调试?