来自两个不同 Linux 发行版的 运行 python locust 脚本出错

Error in running python locust script from two different Linux Distribution

我写了一个 locust 脚本来测试网站。 脚本很简单,就是一个请求重复几次。

在装有 Linux Mint 和 Python 2.7.6 的虚拟机中,脚本以正确的方式工作,正如我想要的那样。

例如,我运行没有Web界面的脚本如下:

locust --no-web -n 10 -c 1 -r 1 -f /path/to/file/file_test.py

并且我在终端中获得了正确的统计数据 window。

当我在另一台装有 CentOS 和 Python 2.7.11 的虚拟机上 运行 执行相同的脚本时,出现以下错误:

[2016-05-20 12:26:03,954] nix/ERROR/stderr: Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/locust/core.py", line 267, in run
    self.execute_next_task()
  File "/usr/local/lib/python2.7/site-packages/locust/core.py", line 293, in execute_next_task
    self.execute_task(task["callable"], *task["args"], **task["kwargs"])
  File "/usr/local/lib/python2.7/site-packages/locust/core.py", line 305, in execute_task
    task(self, *args, **kwargs)
  File "/data/IVV/multi_benchmark/locust_scripts/OD_skip_top_multi_query.py", line 15, in query1
    self.client.get(QUERY, verify=False)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 487, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/locust/clients.py", line 113, in request
    response = self._send_request_safe_mode(method, url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/locust/clients.py", line 157, in _send_request_safe_mode
    return requests.Session.request(self, method, url, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/requests/adapters.py", line 403, in send
    timeout=timeout
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 578, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 351, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py", line 814, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/connection.py", line 289, in connect
    ssl_version=resolved_ssl_version)
  File "/usr/local/lib/python2.7/site-packages/requests/packages/urllib3/util/ssl_.py", line 308, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/lib/python2.7/ssl.py", line 352, in wrap_socket
    _context=self)
TypeError: __init__() got an unexpected keyword argument 'server_hostname'
[2016-05-20 12:26:04,911] nix/INFO/locust.runners: All locusts hatched: MyLocust: 1
[2016-05-20 12:26:04,911] nix/INFO/locust.runners: Resetting stats

你能帮我理解这个问题吗? 非常感谢。

这似乎是 urllib3 中的一个已知问题,与您的脚本无关。参见 https://github.com/shazow/urllib3/issues/482