gpt4 book ai didi

php - 统一码编码错误 : 'ascii' codec can't encode characters in position 360-362: ordinal not in range(128)

转载 作者:太空宇宙 更新时间:2023-11-04 02:50:37 28 4
gpt4 key购买 nike

我尝试通过 PHP 运行 python 我一直在获取

UnicodeEncodeError: 'ascii' codec can't encode characters in position 360-362: ordinal not in range(128)

我试过了

php

$command = "python ".public_path().'/python/start_clientsim.py 2>&1';
$result = exec($command);

python (start_clientsim.py)

import paramiko
import time
import sys
import os
import pdb

# Note
# sudo pip install --user paramiko


ip = "172.1.1.1"
un = "root"
pw = "123"
key_filename='/Users/keys/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")
cmd_io("start subscriber-group dth-sub start-traffic udp")
cmd_io("exit")

最佳答案

尝试运行

putenv("PYTHONIOENCODING=utf-8");

在从 PHP 执行 shell 命令之前。参见 https://stackoverflow.com/a/7363085/197921了解详情。

关于php - 统一码编码错误 : 'ascii' codec can't encode characters in position 360-362: ordinal not in range(128),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43990212/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com