rewritten query_portal using requests

This commit is contained in:
Emmanuel Viennet 2021-08-21 00:49:36 +02:00
parent 494f84d4f2
commit b8cb462d9a
2 changed files with 9 additions and 10 deletions

View File

@ -355,7 +355,7 @@ def module_edit(module_id=None, REQUEST=None):
"""SELECT ue.acronyme, mat.*, mat.id AS matiere_id """SELECT ue.acronyme, mat.*, mat.id AS matiere_id
FROM notes_matieres mat, notes_ue ue FROM notes_matieres mat, notes_ue ue
WHERE mat.ue_id = ue.id 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 ORDER BY ue.numero, mat.numero
""", """,
{"formation_id": Mod["formation_id"]}, {"formation_id": Mod["formation_id"]},

View File

@ -38,14 +38,15 @@ import numbers
import os import os
import pydot import pydot
import re import re
import requests
import six import six
import six.moves._thread import six.moves._thread
import sys import sys
import time import time
import types import types
import unicodedata import unicodedata
import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error import 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.error, six.moves.urllib.parse
from xml.etree import ElementTree from xml.etree import ElementTree
STRING_TYPES = six.string_types STRING_TYPES = six.string_types
@ -734,17 +735,15 @@ def query_portal(req, msg="Portail Apogee", timeout=3):
log("query_portal: %s" % req) log("query_portal: %s" % req)
try: try:
f = six.moves.urllib.request.urlopen(req, timeout=timeout) # seconds / request r = requests.get(req, timeout=timeout) # seconds / request
except: except:
log("query_portal: can't connect to %s" % msg) log("query_portal: can't connect to %s" % msg)
return "" return ""
try: if r.status_code != 200:
data = f.read() log(f"query_portal: http error {r.status_code}")
except: return "" # XXX ou raise exception ?
log("query_portal: error reading from %s" % msg)
data = ""
return data return r.text
def AnneeScolaire(sco_year=None): def AnneeScolaire(sco_year=None):