From b8cb462d9aef8962b4f6cfb82538262de5cdb77d Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Sat, 21 Aug 2021 00:49:36 +0200 Subject: [PATCH] rewritten query_portal using requests --- app/scodoc/sco_edit_module.py | 2 +- app/scodoc/sco_utils.py | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/scodoc/sco_edit_module.py b/app/scodoc/sco_edit_module.py index e04d358fa..f3ebed08c 100644 --- a/app/scodoc/sco_edit_module.py +++ b/app/scodoc/sco_edit_module.py @@ -355,7 +355,7 @@ def module_edit(module_id=None, REQUEST=None): """SELECT ue.acronyme, mat.*, mat.id AS matiere_id FROM notes_matieres mat, notes_ue ue WHERE mat.ue_id = ue.id - AND ue.formation_id = %(formation_id)d + AND ue.formation_id = %(formation_id)s ORDER BY ue.numero, mat.numero """, {"formation_id": Mod["formation_id"]}, diff --git a/app/scodoc/sco_utils.py b/app/scodoc/sco_utils.py index 49a57a246..853a23b15 100644 --- a/app/scodoc/sco_utils.py +++ b/app/scodoc/sco_utils.py @@ -38,14 +38,15 @@ import numbers import os import pydot import re +import requests import six import six.moves._thread import sys import time import types import unicodedata -import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error -import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse +import six.moves.urllib.parse, six.moves.urllib.error +import six.moves.urllib.error, six.moves.urllib.parse from xml.etree import ElementTree STRING_TYPES = six.string_types @@ -734,17 +735,15 @@ def query_portal(req, msg="Portail Apogee", timeout=3): log("query_portal: %s" % req) try: - f = six.moves.urllib.request.urlopen(req, timeout=timeout) # seconds / request + r = requests.get(req, timeout=timeout) # seconds / request except: log("query_portal: can't connect to %s" % msg) return "" - try: - data = f.read() - except: - log("query_portal: error reading from %s" % msg) - data = "" + if r.status_code != 200: + log(f"query_portal: http error {r.status_code}") + return "" # XXX ou raise exception ? - return data + return r.text def AnneeScolaire(sco_year=None):