Skip to main content
 首页 » 编程设计

python之使用 Python 远程执行时 Curl 不打印

2024年09月07日7findumars

下面的代码没有打印任何东西。请让我知道脚本有什么问题。

import paramiko 
 
ip='ip' 
port=22 
username='userid' 
password='passwd' 
 
cmd="""curl https://www.facebook.com""" 
 
try: 
    ssh=paramiko.SSHClient() 
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) 
    ssh.connect(ip,port,username,password) 
    stdin,stdout,stderr=ssh.exec_command(cmd) 
    outlines=stdout.readlines() 
    resp=''.join(outlines) 
    print(resp) 
 
except: 
    print("failed on login.")  

请您参考如下方法:

cmd 包含一个 non-breaking space而不是普通空间。删除 curl 命令后看起来像空格的内容,并将其替换为真正的空格字符。