Spaces:
Sleeping
Sleeping
File size: 1,726 Bytes
e73c9c1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import requests
from public_api.public_api_auth import login
def get_location_status(session_data, warehouse_id, stoloc):
url = "http://euwdsw202em01:4660/api/inventory/v1/locationStatus"
session = session_data["wms_auth"]
# Pass everything from kwargs directly to the API
params = {
"stoloc":stoloc
}
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
try:
response = session.get(url, params=params, headers=headers, verify=False)
# Standardized 401 Session Recovery
if response.status_code == 401:
print("Session expired. Re-logging in...")
new_session, new_wh, success = login()
if success:
session_data["wms_auth"] = new_session
session_data["user_warehouse_id"] = new_wh
response = new_session.get(url, params=params, headers=headers, verify=False)
# SUCCESS: Return data and the status code for main.py to inspect
if response.status_code == 200:
try:
res_json = response.json()
all_data = res_json.get("data", [])
return {"data": all_data, "error": None, "status_code": 200}
except ValueError:
return {"data": [], "error": "Invalid JSON format", "status_code": 200}
print(f"Location API response code: {response.status_code}\n{response.text}")
return {"data": [], "error": f"Location API Error: {response.text}"}
except Exception as e:
print(f"Location API exception: {e}")
return {"data": [], "error": f"Location API Connection failed: {str(e)}"} |