SonarQube API Using Python

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension): SonarQube
  • how is SonarQube deployed: zip, Docker, Helm: NA
  • what are you trying to achieve: SonarQube API
  • what have you tried so far to achieve this

Do not share screenshots of logs – share the text itself (bonus points for being well-formatted)!

Hi,
I am trying to get the test coverage from Sonarqube project using SonarQube API in Python but i am getting error

403 Forbidden

403 Forbidden


Microsoft-Azure-Application-Gateway/v2

Command Used

self._sonar_headers = {
“Authorization”: f"Bearer {token}",
“Accept”: “application/vnd.github+json”,
}

url = f’{self.sonar_url_name}/sonarqube/api/measures/component?component={component_key}&metricKeys=coverage’
response = requests.get(url, headers=self._sonar_headers)

I have verified Sonar token as well. If i run curl command to fetch api results then its working whereas if i am using python then i am getting this error.

Hi,

Welcome to the community!

This really seems more like a Python question than a SonarQube question. And with the former, we can’t help you.

 
Ann

Hi,

for the use of Python with the Sonarqube api you may use or get inspired by

Gilbert