|
|
|
@ -599,7 +599,7 @@ class Prediksi:
|
|
|
|
# Try to sign in again
|
|
|
|
# Try to sign in again
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
signin_res = await self.sign_in()
|
|
|
|
signin_res = await self.sign_in()
|
|
|
|
if getattr(self, "access_token", None):
|
|
|
|
if self.access_token:
|
|
|
|
return signin_res
|
|
|
|
return signin_res
|
|
|
|
except Exception as signin_exc:
|
|
|
|
except Exception as signin_exc:
|
|
|
|
print(f"Sign-in failed after sign-out: {signin_exc}")
|
|
|
|
print(f"Sign-in failed after sign-out: {signin_exc}")
|
|
|
|
@ -610,7 +610,7 @@ class Prediksi:
|
|
|
|
|
|
|
|
|
|
|
|
On success updates self.access_token and returns it. Returns None on failure.
|
|
|
|
On success updates self.access_token and returns it. Returns None on failure.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
if not getattr(self, "refresh_token", None):
|
|
|
|
if not self.refresh_token:
|
|
|
|
print("No refresh token available to refresh access token.")
|
|
|
|
print("No refresh token available to refresh access token.")
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
@ -641,7 +641,7 @@ class Prediksi:
|
|
|
|
endpoint = f"{url}/main/number-of-failures/{assetnum}/{int(year)}/{int(year)}"
|
|
|
|
endpoint = f"{url}/main/number-of-failures/{assetnum}/{int(year)}/{int(year)}"
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
current_token = getattr(self, "access_token", None)
|
|
|
|
current_token = self.access_token
|
|
|
|
response = await client.get(
|
|
|
|
response = await client.get(
|
|
|
|
endpoint,
|
|
|
|
endpoint,
|
|
|
|
timeout=30.0,
|
|
|
|
timeout=30.0,
|
|
|
|
@ -650,7 +650,7 @@ class Prediksi:
|
|
|
|
response.raise_for_status()
|
|
|
|
response.raise_for_status()
|
|
|
|
return response.json()
|
|
|
|
return response.json()
|
|
|
|
except httpx.HTTPStatusError as e:
|
|
|
|
except httpx.HTTPStatusError as e:
|
|
|
|
status = getattr(e.response, "status_code", None)
|
|
|
|
status = e.response.status_code
|
|
|
|
# If we get a 401 or 403, try to refresh the access token and retry once
|
|
|
|
# If we get a 401 or 403, try to refresh the access token and retry once
|
|
|
|
if status in (401, 403):
|
|
|
|
if status in (401, 403):
|
|
|
|
print(f"Received {status} from reliability API, attempting to refresh/re-login...")
|
|
|
|
print(f"Received {status} from reliability API, attempting to refresh/re-login...")
|
|
|
|
@ -660,7 +660,7 @@ class Prediksi:
|
|
|
|
if not new_access:
|
|
|
|
if not new_access:
|
|
|
|
print("Refresh failed, attempting full sign-in...")
|
|
|
|
print("Refresh failed, attempting full sign-in...")
|
|
|
|
await self.sign_in()
|
|
|
|
await self.sign_in()
|
|
|
|
new_access = getattr(self, "access_token", None)
|
|
|
|
new_access = self.access_token
|
|
|
|
|
|
|
|
|
|
|
|
if new_access:
|
|
|
|
if new_access:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
@ -985,7 +985,7 @@ async def main(RELIABILITY_APP_URL=RELIABILITY_APP_URL, assetnum=None, token=Non
|
|
|
|
# If token not provided, sign in to obtain access_token/refresh_token
|
|
|
|
# If token not provided, sign in to obtain access_token/refresh_token
|
|
|
|
if token is None:
|
|
|
|
if token is None:
|
|
|
|
signin_res = await prediksi.sign_in()
|
|
|
|
signin_res = await prediksi.sign_in()
|
|
|
|
if not getattr(prediksi, "access_token", None):
|
|
|
|
if not prediksi.access_token:
|
|
|
|
print("Failed to obtain access token; aborting.")
|
|
|
|
print("Failed to obtain access token; aborting.")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
|