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

**URL:** <https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943>\
**Category:** SonarQube Server / Community Build\
**Tags:** python, api, ssl\
**Created:** [October 3, 2022, 6:36pm UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943 "2022-10-03T18:36:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joe\_Seabreeze](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/joe_seabreeze/32/37781_2.png) [@Joe\_Seabreeze](https://community.sonarsource.com/u/Joe_Seabreeze)\
**Post date:** [October 3, 2022, 6:36pm UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943/1 "2022-10-03T18:36:31Z")

</div>

Must-share information (formatted with [Markdown](https://commonmark.org/help/)):

- 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:

```auto
URL = 'https://company.name.com/sonar'
USERNAME = 'admin'
PASSWORD = 'admin'
CERT = 'company.name.com.pem'

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()

    print(version)

```

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

```auto
curl --cacert company.name.com.pem -X GET https://company.name.com/sonar/api/server/version

```

---

<div class="post-metadata">

**Author:** ![Hendrik\_Buchwald](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/hendrik_buchwald/32/69290_2.png) [@Hendrik\_Buchwald](https://community.sonarsource.com/u/Hendrik_Buchwald)\
**Post date:** [October 4, 2022, 3:45pm UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943/2 "2022-10-04T15:45:04Z")

</div>

Hello Joe and welcome to the community!

Are you talking about [this](https://github.com/shijl0925/python-sonarqube-api) 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.

---

<div class="post-metadata">

**Author:** ![Joe\_Seabreeze](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/joe_seabreeze/32/37781_2.png) [@Joe\_Seabreeze](https://community.sonarsource.com/u/Joe_Seabreeze)\
**Post date:** [October 4, 2022, 3:54pm UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943/3 "2022-10-04T15:54:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon67236913](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@anon67236913](https://community.sonarsource.com/u/anon67236913)\
**Post date:** [October 5, 2022, 9:17am UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943/4 "2022-10-05T09:17:17Z")

</div>

Hi,

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

> **[sonar-tools](https://pypi.org/project/sonar-tools/)**
>
> A collection of utility scripts for SonarQube

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

Gilbert

---

<div class="post-metadata">

**Author:** ![Hendrik\_Buchwald](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/hendrik_buchwald/32/69290_2.png) [@Hendrik\_Buchwald](https://community.sonarsource.com/u/Hendrik_Buchwald)\
**Post date:** [October 5, 2022, 9:26am UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943/5 "2022-10-05T09:26:51Z")

</div>

You can just use a library like [requests](https://pypi.org/project/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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/31083_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [October 12, 2022, 9:27am UTC](https://community.sonarsource.com/t/python-api-how-to-connect-to-sq-server-which-uses-ssl/73943/6 "2022-10-12T09:27:44Z")

</div>

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