File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change @@ -75,9 +75,16 @@ def migrate(self):
75
75
def _post (self , data ):
76
76
tries = 0
77
77
while tries < self .max_tries :
78
- r = requests .post (f'http://{ self .host } :{ self .port } /api/processCitation' , data = data )
78
+ with requests .Session () as s :
79
+ r = s .post (
80
+ f'http://{ self .host } :{ self .port } /api/processCitation' ,
81
+ data = data ,
82
+ headers = {'Connection' : 'close' }
83
+ )
84
+ if r .status_code in [200 , 204 ]:
85
+ return r .content .decode ("utf-8" )
79
86
if r .status_code != 503 :
80
- return r
87
+ raise RuntimeError ( f" { r . status_code } { r . reason } \n { r . content } " )
81
88
tries += 1
82
89
if tries < self .max_tries :
83
90
time .sleep (self .retry_wait )
@@ -87,8 +94,8 @@ def parse_ref_str_to_tei_dict(self, ref_str):
87
94
cache = self .get_cache ()
88
95
d = cache .get (ref_str )
89
96
if d is None : # potential multiple recomputation in multithreading case
90
- r = self ._post (data = {'citations' : ref_str })
91
- d = xmltodict .parse (r . content . decode ( "utf-8" ) )
97
+ content = self ._post (data = {'citations' : ref_str })
98
+ d = xmltodict .parse (content )
92
99
d = to_normal_dict (d )
93
100
cache [ref_str ] = d
94
101
return d
You can’t perform that action at this time.
0 commit comments