@@ -90,16 +90,12 @@ def login(self, username="", password=""):
9090 _xsrf_token (str): The XSRF token to be used for subsequent API requests.
9191
9292 """
93- endpoint : str = "login"
9493 _username : str = self .config .active_config ["username" ] or username
9594 _password : str = self .config .active_config ["password" ] or password
9695 _auth : Dict [str , str ] = {"username" : _username , "password" : _password }
9796
9897 # Attempt to login to the CloudEndure API via a POST request.
99- response : requests .Response = self .api_call (
100- "login" , "post" , data = json .dumps (_auth )
101- )
102- # response: requests.Response = self.session.post(f'{self.api_endpoint}/{endpoint}', json=_auth)
98+ response : requests .Response = self .api_call ("login" , "post" , data = json .dumps (_auth ))
10399
104100 # Check whether or not the request was successful.
105101 if response .status_code not in [200 , 307 ]:
@@ -117,8 +113,11 @@ def login(self, username="", password=""):
117113 )
118114 raise CloudEndureUnauthorized ()
119115
120- # print('response: ', response, response.cookies)
121- _xsrf_token : str = str (response .cookies ["XSRF-TOKEN" ])
116+ # Grab the XSRF token received from the response, as stored in cookies.
117+ # _xsrf_token: str = str(response.cookies["XSRF-TOKEN"])
118+ _xsrf_token : str = str (response .cookies .get ("XSRF-TOKEN" , "" ))
119+ if not _xsrf_token :
120+ raise CloudEndureException ("Failed to fetch a token from CloudEndure!" )
122121
123122 # Strip the XSRF token of wrapping double-quotes from the cookie.
124123 if _xsrf_token .startswith ('"' ) and _xsrf_token .endswith ('"' ):
0 commit comments