Python API - how to connect to SQ server which uses SSL

Must-share information (formatted with Markdown):

  • which versions are you using: 9.6
  • what are you trying to achieve: use Python api to retrieve metrics
  • what have you tried so far to achieve this: just trying to authenticate with username/pw and url.

I create a SonarQubeClient() with url, username, password, and cert (.pem). Then I try any api request and get the following error: Max retries exceeded with url: /sonar/api/server/version (caused by SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certification verify failed: unable to get local issuer certificate (_ssl.c:1129)’)))

The basics of the code is this:

URL = ''
USERNAME = 'admin'
PASSWORD = 'admin'
CERT = ''

cert_path = Path(CERT)

if cert_path.is_file():
    sonar = SonarQubeClient(sonarqube_url=URL, username=USERNAME, password=PASSWORD, cert=CERT)

    version = sonar.server.get_server_version()


The code doesn’t work but a curl command does:

curl --cacert -X GET

Hello Joe and welcome to the community!

Are you talking about this library? It is not written or maintained by us, so you will have to redirect your question to the maintainer of the library. After a quick look at their code, it does not seem to me that the cert attribute is actually used anywhere.

I see. So Sonarqube company doesn’t offer a Python api? My mistake for not noticing.


instead of implementing something yourself this could also be an option !?

It is not provided by Sonarsource itself, but is created by a Sonarsource employee.


You can just use a library like requests to talk to the API, no need to use a specific library for that. The API documentation is linked in the footer of your SonarQube instance.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.