使用 python 从 bugzilla 获取错误

Get bugs from bugzilla using python

我正在尝试从 bugzilla rest API 中获取错误到数据库。我的代码如下。

import requests
import json

URL = "https://bugzilla.mozilla.org/rest/"

API_KEY = "key"

headers = {"Content-type": "application/json"}
params = {
              "username": "email",
              "password": "password",
              "apikey": API_KEY,
          }

# r = requests.get(URL + 'login/', headers = headers, params = params)
# print(r)

resp = requests.post(URL + "bug/" , headers = headers, params = params)


if resp.status_code != 200:
    print('error: ' + str(resp.status_code))
else:
    print('Success')
    print(resp)

当我尝试这个时,我得到了响应 404。

有人请指引我到正确的路径。

https://resttesttest.com/ I found the answer. Bugzilla API can be authenticate just by API-KEY. So I removed username and password from params dict. It seems I have an error in concatenating the URL too. I just used "https://bugzilla.mozilla.org/rest/bug/35" 上寻找关于 bug_id 35 的错误报告之后。然后 json.load(resp.text) 给出了 json 的对象错误报告。最终代码如下所示。

import requests
import json

URL = "https://bugzilla.mozilla.org/rest/bug/35"

API_KEY = "key"

headers = {"Content-type": "application/json"}
params = {
              "api_key": API_KEY,
          }

resp = requests.get(URL , headers = headers, params = params)


if resp.status_code != 200:
    print('error: ' + str(resp.status_code))
else:
    print('Success')
    print(json.loads(resp.text))