From 9664464413b7cd59f861eff01148454974e23030 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 4 Dec 2016 10:02:10 +0200 Subject: sync: use requests response.json() directly instead of json.loads This should ensure requests will handle UTF-8 fully correctly for us Suggested-by: Doug Freed --- backend/lib/sync.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/lib/sync.py b/backend/lib/sync.py index 22419bf..2d6244c 100644 --- a/backend/lib/sync.py +++ b/backend/lib/sync.py @@ -1,5 +1,4 @@ import xml.etree.ElementTree as ET -from flask import json import requests from .. import app, db from .models import Category, Maintainer, Package, PackageVersion @@ -111,7 +110,7 @@ def sync_categories(): url = pkg_url_base + "categories.json" data = http_session.get(url) # TODO: Handle response error (if not data) - categories = json.loads(data.text) + categories = data.json() existing_categories = {} # TODO: Use UPSERT instead (on_conflict_do_update) if we can rely on postgresql:9.5 for cat in Category.query.all(): @@ -131,7 +130,7 @@ def sync_packages(): if not data: print("No JSON data for category %s" % category.name) # FIXME: Better handling; mark category as inactive/gone? continue - packages = json.loads(data.text)['packages'] + packages = data.json()['packages'] # TODO: Use UPSERT instead (on_conflict_do_update) existing_packages = {} for pkg in Package.query.all(): @@ -151,5 +150,5 @@ def sync_versions(): print("No JSON data for package %s" % package.full_name) # FIXME: Handle better; e.g mark the package as removed if no pkgmove update continue from pprint import pprint - pprint(json.loads(data.text)) + pprint(data.json()) break -- cgit v1.2.3-65-gdbad