@@ -47,7 +47,7 @@ def parse_api_response(name: str, response: requests.Response):
4747 # We got a successful HTTP response. It worked. Return the full response
4848 try :
4949 result = json .loads (response .text )
50- except json .decoder .JSONDecodeError as e :
50+ except json .decoder .JSONDecodeError :
5151 print (response .text )
5252 raise RuntimeError (f'Failed to JSON decode the response for API request { name } ' )
5353
@@ -79,15 +79,17 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}):
7979 url = f'{ domjudge_webapp_folder_or_api_url } /{ name } '
8080 parsed = urlparse (domjudge_webapp_folder_or_api_url )
8181 auth = None
82- if parsed .username or parsed .password :
82+ if parsed .username and parsed .password :
8383 auth = (parsed .username , parsed .password )
8484
8585 try :
8686 if method == 'GET' :
8787 response = requests .get (url , headers = headers , verify = ca_check , auth = auth )
8888 elif method == 'PUT' :
8989 response = requests .put (url , headers = headers , verify = ca_check , json = jsonData , auth = auth )
90- except requests .exceptions .SSLError as e :
90+ else :
91+ raise RuntimeError ("Method not supported" )
92+ except requests .exceptions .SSLError :
9193 ca_check = not confirm (
9294 "Can not verify certificate, ignore certificate check?" , False )
9395 if ca_check :
@@ -99,6 +101,7 @@ def do_api_request(name: str, method: str = 'GET', jsonData: dict = {}):
99101 raise RuntimeError (e )
100102 return parse_api_response (name , response )
101103
104+
102105def upload_file (name : str , apifilename : str , file : str , data : dict = {}):
103106 '''Upload the given file to the API at the given path with the given name.
104107
@@ -128,7 +131,7 @@ def upload_file(name: str, apifilename: str, file: str, data: dict = {}):
128131 try :
129132 response = requests .post (
130133 url , files = files , headers = headers , data = data , verify = ca_check )
131- except requests .exceptions .SSLError as e :
134+ except requests .exceptions .SSLError :
132135 ca_check = not confirm (
133136 "Can not verify certificate, ignore certificate check?" , False )
134137 if ca_check :
0 commit comments