Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在JMeter中导入python模块_Python_Jmeter_Sftp - Fatal编程技术网

无法在JMeter中导入python模块

无法在JMeter中导入python模块,python,jmeter,sftp,Python,Jmeter,Sftp,您好,我正在尝试使用JMeter测试sftp服务器的性能,同时用python代码将文件上载到服务器 上载文件的我的代码: import socket import os import time import threading import paramiko #------- #defining the variables: host, port, user, password, serverpath, localpath, uploadDataAmount and sleepTime #he

您好,我正在尝试使用JMeter测试sftp服务器的性能,同时用python代码将文件上载到服务器

上载文件的我的代码:

import socket
import os
import time
import threading
import paramiko

#-------
#defining the variables: host, port, user, password, serverpath, localpath, uploadDataAmount and sleepTime
#here I just define the variables it is not related to the problem. 
#I didn't add it because it contains ip and password of the server. 
#-------

transport = paramiko.Transport((host, port))
transport.connect(None, user, password)
sftp = paramiko.SFTPClient.from_transport(transport)


fileServer = sftp.open(serverpath, 'ab')
fileClient = open(localpath, 'rb')
try:
    data = fileClient.read(uploadDataAmount)
    while(data != b''):
        fileServer.write(data)
        size = str(fileServer._get_size())
        print("file size in bytes before going to sleep: "+size)
        time.sleep(sleepTime)
        print("waking up ")
        data = fileClient.read(uploadDataAmount)
finally:
    fileClient.close()
    fileServer.close()

if sftp:
    sftp.close()
if transport:
    transport.close()
我在visualstudio中测试了python代码,效果很好

我是JMeter新手,所以我不确定它是如何工作的,为了使它能够与python代码一起工作,我下载了jython.jar文件,并将其添加到JMeter目录中的lib目录中。但是我的代码使用paramiko包,因此当我尝试运行它时,jmeter返回错误:
响应消息:javax.script.ScriptException:ImportError:中没有名为paramiko的模块

我尝试将paramiko导入更改为:

import sys

sys.path.append(
    "C:\\Users\\YShay\\AppData\\Local\\Programs\\Python\\Python38\\Lib\\site-packages")
from paramiko import Transport, SFTPClient
同样,它在VisualStudio中运行良好

但是我在jmeter中得到了以下错误:
响应消息:javax.script.ScriptException:ImportError:中没有名为six的模块


有人能帮我吗?如何在jmeter的python代码中导入paramiko?

我的期望是您将这个
paramiko
模块安装到python中,并且您需要将其安装到Jython中,以便能够与jmeter的JSR223采样器一起使用

比如:

jython -m pip install paramiko
更多信息:


一般来说,你的方法不是最好的,所以考虑切换到Groovy,你可以通过库获得SSH/SFTP连接。 如果你只需要使用SFTP协议将文件上传到服务器,你可以考虑使用,这样你就不必编写一行代码,并将“异类”Python带到纯java环境中。查看文章以获取全面信息