Skip to content

Commit

Permalink
Stop using FancyURLopener in gerrit plugin
Browse files Browse the repository at this point in the history
Fix: #385
  • Loading branch information
lukaszachy committed Feb 4, 2025
1 parent bb23ea5 commit 39dd2b8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions did/plugins/gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import urllib.request
from datetime import datetime

import requests

from did.base import TODAY, Config, ReportError
from did.stats import Stats, StatsGroup
from did.utils import log, pretty
Expand Down Expand Up @@ -63,7 +65,6 @@ class Gerrit(object):
"""

def __init__(self, baseurl, prefix):
self.opener = urllib.request.FancyURLopener()
self.baseurl = baseurl
self.prefix = prefix

Expand All @@ -75,20 +76,19 @@ def join_URL_frags(base, query):

def get_query_result(self, url):
log.debug('url = {0}'.format(url))
res = self.opener.open(url)
if res.getcode() != 200:
res = requests.get(url)
if res.status_code() != 200:
raise IOError(
'Cannot retrieve list of changes ({0})'.format(res.getcode()))
'Cannot retrieve list of changes ({0})'.format(res.status_code))

# see https://code.google.com/p/gerrit/issues/detail?id=2006
# for explanation of skipping first four characters
json_str = res.read()[4:].strip()
json_str = res.text[4:].strip()
try:
data = json.loads(json_str)
except ValueError:
log.exception('Cannot parse JSON data:\n%s', json_str)
raise
res.close()

return data

Expand Down

0 comments on commit 39dd2b8

Please # to comment.