【发布时间】:2018-11-17 11:39:06
【问题描述】:
我正在尝试通过 ssh local 为 Linux 机器远程运行 Python 脚本,但是当我的脚本正在读取 txt 文件时出现错误,该脚本在我的 Python IDE 上运行良好且没有错误。
我正在使用ssh root@ip_adress python2 < script.py 运行脚本。
我正在读取 txt 文件的脚本的一部分:
import os
import smtplib
with open("file.txt") as fp:
conteudo = fp.readlines()
conteudo = [linhas.strip() for linhas in conteudo]
错误:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
IOError: [Errno 2] No such file or directory: 'file.txt'
【问题讨论】:
-
您将不得不重写问题,“脚本在终端外运行良好”在这里应该是什么意思?
file.txt是否真的存在于远程机器上? -
@tink file.txt 只在我的电脑上。我需要在我的服务器上保存该文件吗?
-
当然。通过 ssh 执行 python 脚本不会让它访问调用它的机器上的文件,它只能看到它正在运行的机器上的东西。
-
P.S.:看到你使用
ssh root@让我胃痛。 ;) -
@tink 有没有办法让它使用我电脑上的文件?我应该用什么来代替 ssh root@?我对这个 xD 很陌生