pythonbugzilla

Get bugs from bugzilla using python


I am trying to get bugs to a db from bugzilla rest API. My code is given below.

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)

When I try this I get Response 404.

Someone please direct me to the correct path.


Solution

  • After poking aroung 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" to get the bug report on bug_id 35. Then json.load(resp.text) gave the json object of the bug report. Final code looks like this.

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