summaryrefslogtreecommitdiff
path: root/pgcommitfest/commitfest/ajax.py
diff options
context:
space:
mode:
authorMagnus Hagander2019-02-05 21:56:05 +0000
committerMagnus Hagander2019-02-05 21:56:05 +0000
commit83edf49e86d2db5d7a75f6c1068d3e62bda99923 (patch)
tree799497ad753729054c6becfb82f0b13fcf7c4c5d /pgcommitfest/commitfest/ajax.py
parentd9a2b88e70ba2fb5755bc330c6dcaee87a6a7ad3 (diff)
Switch to using requests for archives API
This should fix some unicode issues
Diffstat (limited to 'pgcommitfest/commitfest/ajax.py')
-rw-r--r--pgcommitfest/commitfest/ajax.py48
1 files changed, 18 insertions, 30 deletions
diff --git a/pgcommitfest/commitfest/ajax.py b/pgcommitfest/commitfest/ajax.py
index b65de8d..3ec76ea 100644
--- a/pgcommitfest/commitfest/ajax.py
+++ b/pgcommitfest/commitfest/ajax.py
@@ -6,9 +6,7 @@ from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.db import transaction
-import httplib
-import socket
-import urllib
+import requests
import json
from pgcommitfest.auth import user_search
@@ -24,36 +22,26 @@ from models import MailThreadAnnotation, PatchHistory
def _archivesAPI(suburl, params=None):
try:
- socket.setdefaulttimeout(settings.ARCHIVES_TIMEOUT)
- if settings.ARCHIVES_PORT != 443:
- h = httplib.HTTPConnection(host=settings.ARCHIVES_SERVER,
- port=settings.ARCHIVES_PORT,
- strict=True,
- timeout=settings.ARCHIVES_TIMEOUT)
- else:
- h = httplib.HTTPSConnection(host=settings.ARCHIVES_SERVER,
- port=settings.ARCHIVES_PORT,
- strict=True,
- timeout=settings.ARCHIVES_TIMEOUT)
- if params:
- url = "%s?%s" % (suburl, urllib.urlencode(params))
- else:
- url = suburl
- h.request('GET', url, headers={
- 'Host': settings.ARCHIVES_HOST,
- })
- resp = h.getresponse()
- if resp.status != 200:
- if resp.status == 404:
+ resp = requests.get("http{0}://{1}:{2}{3}".format(settings.ARCHIVES_PORT == 443 and 's' or '',
+ settings.ARCHIVES_SERVER,
+ settings.ARCHIVES_PORT,
+ suburl),
+ params=params,
+ headers={
+ 'Host': settings.ARCHIVES_HOST,
+ },
+ timeout=settings.ARCHIVES_TIMEOUT,
+ )
+ if resp.status_code != 200:
+ if resp.status_code == 404:
raise Http404()
- raise Exception("JSON call failed: %s" % resp.status)
+ raise Exception("JSON call failed: %s" % resp.status_code)
- r = json.load(resp)
- resp.close()
- h.close()
- except socket.error, e:
+ return resp.json()
+ except Http404:
+ raise
+ except Exception as e:
raise Http503("Failed to communicate with archives backend: %s" % e)
- return r
def getThreads(request):
search = request.GET.has_key('s') and request.GET['s'] or None