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
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"]},

View File

@ -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):