mac环境下locust安装问题记录

系统:macOS Catalina 10.15.5。

locust需要提前安装配置好python3.6及以上版本,具体操作网上很多也没什么坑。

1.先尝试使用pip命令安装

 python3 -m pip install locustio

显示:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None,
 status=None)) after connection broken by 'SSLError(SSLCertVerificationError(1, 
'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed 
certificate in certificate chain (_ssl.c:1123)'))': /simple/locustio/

2.尝试在github(https://github.com/locustio/locust)上下载

下载压缩包到任意路径然后运行

python3 setup.py install

进行安装,失败,显示某个包下载失败并且找不到替代的。

error: Could not find suitable distribution for Requirement.parse('Flask-BasicAuth>=0.2.0')

3.根据前两次失败来看应该是源的问题,所以我尝试换源,网上推荐的源:

http://mirrors.aliyun.com/pypi/simple/ 阿里云

https://pypi.mirrors.ustc.edu.cn/simple/  中国科技大学

https://pypi.tuna.tsinghua.edu.cn/simple/ 清华大学

http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学

我这里用的阿里的(阿里大法好)

 python3 -m pip install locustio -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com/pypi

安装失败,报了一大堆错,然后我在中间发现了关键的一句

**** Locust package has moved from 'locustio' to 'locust'. Please update your 
reference (or pin your version to 0.14.6 if you dont want to update to 1.0) ****

把locustio换成locust重新安装,

Successfully installed ConfigArgParse-1.2.3 Flask-BasicAuth-0.2.0 Jinja2-2.11.2 
MarkupSafe-1.1.1 Werkzeug-1.0.1 certifi-2020.6.20 chardet-3.0.4 click-7.1.2 flask-
1.1.2 gevent-20.6.2 geventhttpclient-1.4.4 greenlet-0.4.16 idna-2.10 itsdangerous-
1.1.0 msgpack-1.0.0 psutil-5.7.2 pyzmq-19.0.1 requests-2.24.0 six-1.15.0 urllib3-
1.25.9 zope.event-4.4 zope.interface-5.1.0

成功啦!!!

运行locust -h也没有问题。

 

PS:locust 1.0*新版中 HttpLocust类重命名为HttpUser, TaskSet类locust属性重命名为user,Locust类重命名为User而且task_set属性已被移除,改用tasks属性替代(tasks的写法只能是列表或字典),一定要注意别用成task_set,引入HttpLocust会报错提醒你改名了但写task_set只会警告

 warnings.warn("Usage of User.task_set is deprecated since version 1.0. Set the tasks attribute instead "

最后附上一个简单的样例脚本

# coding=utf-8
import requests
from locust import HttpUser,TaskSet,task
from urllib3.exceptions import InsecureRequestWarning
# 禁用安全请求警告
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

class UserBehavior(TaskSet):
    @task(1)
    def baidu(self):
        self.client.get("/")

class WebsiteUser(HttpUser):
    tasks = [UserBehavior]
    min_wait = 3000
    max_wait = 6000

if __name__ == "__main__":
    import os
    os.system("locust -f test_01.py --host=https://www.baidu.com")

 

你可能感兴趣的:(个人笔记)