greg
greg

Reputation: 767

SSL error CERTIFICATE_VERIFY_FAILED with Locust when using Docker

It's my first try at Locus, and unfortunately I don't know Python.

I'm trying a simple request to a valid https server, and I see this error:

SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate

After some research I tried to add this:

import gevent
import geventhttpclient.connectionpool

geventhttpclient.connectionpool.SSLConnectionPool.default_options = {
    "cert_reqs": gevent.ssl.CERT_NONE,
}

or this:

import requests
requests.packages.urllib3.disable_warnings() # disable SSL warnings

I run Locust as instructed:

docker-compose up --scale worker=4

How can I test https sites with Locust?

Thanks in advance

Regards

Upvotes: 8

Views: 10687

Answers (2)

Saikat
Saikat

Reputation: 16710

You can do turn the verification off by adding below method:

def on_start(self):
    """ on_start is called when a Locust start before any task is scheduled """
    self.client.verify = False

Upvotes: 12

Marduk
Marduk

Reputation: 1132

While connecting to a server with a self-signed certificate I had a similar problem. I successfully disabled the certificate verification using the following code (from Locust):

import gevent
from geventhttpclient.url import URL
from geventhttpclient import HTTPClient

def insecure_ssl_context_factory():
    context = gevent.ssl.create_default_context()
    context.check_hostname = False
    context.verify_mode = gevent.ssl.CERT_NONE
    return context

url = URL(server)
http = HTTPClient.from_url(url, insecure=True, ssl_context_factory=insecure_ssl_context_factory)

Upvotes: 1

Related Questions