How to fix error "'WorkerNodes' object has no attribute 'encode'" while runnin

I am trying to do a distributed load generation and coordinate data between workers. There is an exampl

I am trying to do a distributed load generation and coordinate data between workers. There is an example of communicating across nodes from official Locust docs: .py

But locust fails with the following error in master-locust:

[2025-01-29 11:50:24,427] f3d0cd3a1386/INFO/locust.runners: Sending spawn jobs of 1 users at 1.00 spawn rate to 1 ready workers
[2025-01-29 11:50:24,428] f3d0cd3a1386/INFO/locust.util.exception_handler: Exception found on retry 1: -- retry after 1s
[2025-01-29 11:50:24,428] f3d0cd3a1386/ERROR/locust.util.exception_handler: 'WorkerNodes' object has no attribute 'encode'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'
[2025-01-29 11:50:25,431] f3d0cd3a1386/INFO/locust.util.exception_handler: Exception found on retry 2: -- retry after 3s
[2025-01-29 11:50:25,432] f3d0cd3a1386/ERROR/locust.util.exception_handler: 'WorkerNodes' object has no attribute 'encode'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'
[2025-01-29 11:50:28,434] f3d0cd3a1386/INFO/locust.util.exception_handler: Exception found on retry 3: -- retry after 5s
[2025-01-29 11:50:28,435] f3d0cd3a1386/ERROR/locust.util.exception_handler: 'WorkerNodes' object has no attribute 'encode'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'
[2025-01-29 11:50:33,437] f3d0cd3a1386/INFO/locust.util.exception_handler: Retry failed after 3 times.
[2025-01-29 11:50:33,442] f3d0cd3a1386/ERROR/root: Uncaught exception in event handler: 
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/event.py", line 47, in fire
    handler(**kwargs)
  File "/mnt/locust/locustfile.py", line 65, in on_test_start
    environment.runner.send_message("test_users", data, worker)
  File "/opt/venv/lib/python3.12/site-packages/locust/runners.py", line 1185, in send_message
    self.server.send_to_client(Message(msg_type, data, client_id))
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'

[2025-01-29 11:50:34,444] f3d0cd3a1386/INFO/locust.runners: Spawning is complete and report waittime is expired, but not all reports received from workers: {"WebsiteUser": 0} (0 total users)

Seems like the problem appears here:

environment.runner.send_message("test_users", data, worker)

because after excluding 'worker' from parameters the error disappears. But I need to send different data to workers.

Does anyeone have any ideas how to fix this code?

I am trying to do a distributed load generation and coordinate data between workers. There is an example of communicating across nodes from official Locust docs: https://github/locustio/locust/blob/master/examples/custom_messages.py

But locust fails with the following error in master-locust:

[2025-01-29 11:50:24,427] f3d0cd3a1386/INFO/locust.runners: Sending spawn jobs of 1 users at 1.00 spawn rate to 1 ready workers
[2025-01-29 11:50:24,428] f3d0cd3a1386/INFO/locust.util.exception_handler: Exception found on retry 1: -- retry after 1s
[2025-01-29 11:50:24,428] f3d0cd3a1386/ERROR/locust.util.exception_handler: 'WorkerNodes' object has no attribute 'encode'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'
[2025-01-29 11:50:25,431] f3d0cd3a1386/INFO/locust.util.exception_handler: Exception found on retry 2: -- retry after 3s
[2025-01-29 11:50:25,432] f3d0cd3a1386/ERROR/locust.util.exception_handler: 'WorkerNodes' object has no attribute 'encode'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'
[2025-01-29 11:50:28,434] f3d0cd3a1386/INFO/locust.util.exception_handler: Exception found on retry 3: -- retry after 5s
[2025-01-29 11:50:28,435] f3d0cd3a1386/ERROR/locust.util.exception_handler: 'WorkerNodes' object has no attribute 'encode'
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'
[2025-01-29 11:50:33,437] f3d0cd3a1386/INFO/locust.util.exception_handler: Retry failed after 3 times.
[2025-01-29 11:50:33,442] f3d0cd3a1386/ERROR/root: Uncaught exception in event handler: 
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/locust/event.py", line 47, in fire
    handler(**kwargs)
  File "/mnt/locust/locustfile.py", line 65, in on_test_start
    environment.runner.send_message("test_users", data, worker)
  File "/opt/venv/lib/python3.12/site-packages/locust/runners.py", line 1185, in send_message
    self.server.send_to_client(Message(msg_type, data, client_id))
  File "/opt/venv/lib/python3.12/site-packages/locust/util/exception_handler.py", line 13, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.12/site-packages/locust/rpc/zmqrpc.py", line 34, in send_to_client
    self.socket.send_multipart([msg.node_id.encode(), msg.serialize()])
                                ^^^^^^^^^^^^^^^^^^
AttributeError: 'WorkerNodes' object has no attribute 'encode'

[2025-01-29 11:50:34,444] f3d0cd3a1386/INFO/locust.runners: Spawning is complete and report waittime is expired, but not all reports received from workers: {"WebsiteUser": 0} (0 total users)

Seems like the problem appears here:

environment.runner.send_message("test_users", data, worker)

because after excluding 'worker' from parameters the error disappears. But I need to send different data to workers.

Does anyeone have any ideas how to fix this code?

Share Improve this question edited Jan 29 at 13:41 Yako asked Jan 29 at 12:18 YakoYako 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

The worker parameter is supposed to be the string identifier of the worker. You can get this by using WorkerNode.id.

You seem to be passing an object of type WorkerNodes?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745298463a4621287.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信