JSONDecodeError:预期值:尝试访问 SonarQube api/issues/search 时第 2 行第 1 列(字符 1)

问题描述 投票:0回答:0

我正在使用 SonarQube 版本 9.9.0,我正在尝试检索 SonarQube 在一个项目中检测到的问题。我使用了 web api: api/issues/search 并用我的凭据替换了缺失的字段,但我收到以下错误:json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) from the line " json_content = response.json()”。我正在使用下面的代码:

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()
    else:
        print('Error:', response.status_code, response.reason)

另外,当我从回复中得到文本时,它是这样的:

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

<head>
    <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" />
    <title>SonarQube</title>

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

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

    <script>
        window.baseUrl = '';
        window.serverStatus = 'UP';
        window.instance = 'SonarQube';
        window.official = true;
    </script>

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

</html>

你对我能做些什么来让它发挥作用有什么想法吗?或者还有其他方法可以检索 SonnarQube 检测到的问题吗?我知道我可以在他们的网络界面上看到它们,但为了做一些报告,我需要以某种方式提取它们。提前谢谢你。

json request sonarqube webapi
© www.soinside.com 2019 - 2024. All rights reserved.