Locust: Basic authentication

Created on 24 Oct 2019  路  5Comments  路  Source: locustio/locust

Describe the bug


Hi guys! Tried to find the answer for my question among the other issues but couldn't find. I have basic auth in my web application. Could someone send me the example of locustfile.py, how to correctly perform the auth in this case because i have an error all the time ?
Capture
Tried the following many code in internet but it doesn't work. I'm getting this error

[2019-10-24 13:15:52,414] ubuntu/INFO/locust.main: Starting web monitor at *:8089
[2019-10-24 13:15:52,414] ubuntu/INFO/locust.main: Starting Locust 0.12.1
[2019-10-24 13:15:56,312] ubuntu/INFO/locust.runners: Hatching and swarming 10 clients at the rate 1 clients/s...
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: Traceback (most recent call last):
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: File "/opt/odoo10/venv-odoo10/local/lib/python2.7/site-packages/locust/runners.py", line 114, in start_locust
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: locust().run(runner=self)
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: File "/opt/locust/locust/locustfile.py", line 29, in __init__
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: super(AtoutConnectBehavior, self).__init__(*args, **kwargs)
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: File "/opt/locust/locust/OdooLocust/OdooLocust.py", line 72, in __init__
[2019-10-24 13:15:56,388] ubuntu/ERROR/stderr: self._connect()
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: File "/opt/locust/locust/OdooLocust/OdooLocust.py", line 82, in _connect
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: self.rpc.check_login()
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: File "/opt/odoo10/venv-odoo10/local/lib/python2.7/site-packages/openerplib/main.py", line 243, in check_login
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: self.user_id = self.get_service("common").login(self.database, self.login, self.password)
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: File "/opt/odoo10/venv-odoo10/local/lib/python2.7/site-packages/openerplib/main.py", line 180, in proxy
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: result = self.connector.send(self.service_name, method, *args)
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: File "/opt/locust/locust/OdooLocust/OdooLocust.py", line 51, in send
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: raise e
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: URLError: <urlopen error [Errno 111] Connection refused>
[2019-10-24 13:15:56,389] ubuntu/ERROR/stderr: 2019-10-24T13:15:56Z

Error report

 # occurrences      Error                                                                                               
--------------------------------------------------------------------------------------------------------------------------------------------
 3                  Odoo JsonRPC common : login: "URLError(error(111, 'Connection refused'),)"                          
--------------------------------------------------------------------------------------------------------------------------------------------

My Code

def base_auth(self):
    self.client.request(method="GET", url="/", auth=HTTPDigestAuth("admin", "admin"))

on start i call base_auth(self)

Environment settings

  • OS: ubuntu 18.04
  • Python version: 3.6
  • Locust version:
bug invalid needs reproducing

All 5 comments

Does this not work?

def base_auth(self):
    self.client.request(method="GET", url="/", auth=("admin", "admin"))

But this is what we do:

class LoadTestTask(TaskSet):
    def on_start(self):
        self.headers = {
            'Authorization': 'Basic XXXXXXX',
        }

    @task(1)
    def get_something(self):
       self.client.get(name="home_page", url='/', headers=self.headers)

You can generate XXXX yourself. E.g. from here

URLError(error(111, 'Connection refused'),) doesn't sound like something related to Basic Auth. What HTTP client are you using?

WHat did you mean ? How can't i know the type of HTTP client?

Are you using the default HTTP client on HttpLocust or are you using the client from FastHttpLocust, or are you using a custom client?

From the error message you receive, it doesn't sound like it has anything to do with basic auth. It sounds more like you're having some kind of connection error. Have you tried doing an HTTP request using curl from the machine you're running Locust on, to the server you're trying to test against?

Please provide a minimal reproducible code example if you still believe that this is a bug in Locust.

Closing due to lack of activity.

Was this page helpful?
0 / 5 - 0 ratings