JSONDecodeError: Expecting value: line 2 column 1 (char 1) when trying to access api/issues/search

I am using SonarQube version 9.9.0 and I’m trying to retrieve the issues detected by SonarQube in one project. I’ve used the web api: api/issues/search and replaced the missing fields with my credentials, but I get the following error: json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) from the line " json_content = response.json()". I’m using the code below:

import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

def get_issues_from_sonar():
    # Set up the request parameters
    url = 'http://localhost.com:9000/api/issues/search'
    params = {'severities': 'MAJOR,CRITICAL', 'assignees': 'nits', 'pageSize': '-1', 'componentKeys': 'myProjectKey'}
    auth = ('admin', 'myPassword)
    session = requests.Session()
    retry = Retry(connect=3, backoff_factor=0.5)
    adapter = HTTPAdapter(max_retries=retry)
    session.mount('http://', adapter)
    session.mount('https://', adapter)

    response = session.get(url, params=params, auth=auth)

    if response.status_code == requests.codes.ok:
        json_content = response.json()
        print('Error:', response.status_code, response.reason)

Also, when I get the text from the response, it is the following:

<!DOCTYPE html>
<html lang="en">

    <meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="apple-touch-icon" href="/apple-touch-icon.png">
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon-180x180.png">
    <link rel="icon" type="image/x-icon" href="/favicon.ico">
    <meta name="application-name" content="SonarQube" />
    <meta name="msapplication-TileColor" content="#FFFFFF" />
    <meta name="msapplication-TileImage" content="/mstile-512x512.png" />

    <link rel="stylesheet" href="/js/outV5A3AQEU.css" />

    <div id="content">
        <div class="global-loading">
            <i class="spinner global-loading-spinner"></i> 
            <span aria-live="polite" class="global-loading-text">Loading...</span>

        window.baseUrl = '';
        window.serverStatus = 'UP';
        window.instance = 'SonarQube';
        window.official = true;

    <script type="module" src="/js/outL2Z6DMVA.js"></script>


Do you have any ideas of what I could do to make it work? Or are there any other ways to retrieve the issues detected by SonnarQube? I know that I can see them on their web interface, but in order to do some reports I would need to extract them somehow. Thank you in advance.

I’m guessing you also get this when you put this URL in your browser?


What URL do you see when you’re browsing your SonarQube instance normally in the browser?

I have replaced http://localhost.com:9000/api/issues/search with http://localhost:9000/api/issues/search and now it works.

1 Like