Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
b30642d4
Commit
b30642d4
authored
Jan 30, 2020
by
LE GAC Renaud
Browse files
Update InvenioStore.interogate to handle properly RequestException and timeout.
parent
4d6064dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
12 deletions
+8
-12
modules/invenio_tools/inveniostore.py
modules/invenio_tools/inveniostore.py
+8
-12
No files found.
modules/invenio_tools/inveniostore.py
View file @
b30642d4
...
...
@@ -8,7 +8,6 @@ import time
from
.exception
import
CdsException
from
requests.adapters
import
HTTPAdapter
from
requests.exceptions
import
ConnectionError
,
HTTPError
CDS_SEARCH_KEYS
=
(
"req"
,
"cc"
,
"c"
,
"ec"
,
"p"
,
"f"
,
"rg"
,
"sf"
,
"so"
,
"sp"
,
...
...
@@ -60,31 +59,28 @@ class InvenioStore(object):
# close the session
self
.
_session
.
close
()
def
interogate
(
self
,
url
,
params
=
None
):
def
interogate
(
self
,
url
,
timeout
=
10
,
params
=
None
):
"""Interrogate the store using the *URL*.
Args:
url (str): URL string
params (dict): parameters to be send with the URL
timeout (float):
timeout for the HTTP request
Returns:
str: the HTTP response
Raises:
Cds
Exception:
when the server returns connection or HTTP error.
Request
Exception:
something went wrong within the HTTP dialog
"""
self
.
_url
=
url
try
:
r
=
self
.
_session
.
get
(
url
,
params
=
params
)
except
ConnectionError
as
ce
:
raise
CdsException
(
str
(
ce
))
except
HTTPError
as
he
:
raise
CdsException
(
str
(
he
))
r
=
self
.
_session
.
get
(
url
,
timeout
=
timeout
,
params
=
params
)
r
.
raise_for_status
()
r
.
encoding
=
"utf-8"
return
r
.
text
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment