Spaces:
Sleeping
Sleeping
| #inside .env file | |
| #service_url="http://euwdsw202em01:4660/service" | |
| #console_url="http://euwdsw202em01:4660/console" | |
| import requests | |
| from dotenv import load_dotenv | |
| import os | |
| # Load variables from .env file | |
| load_dotenv() | |
| usr_id = os.getenv("usr_id") | |
| password = os.getenv("password") | |
| def login(): | |
| url = "http://euwdsw202em01:4660/ws/auth/login" | |
| # Query parameters | |
| params = { | |
| "usr_id": usr_id, | |
| "password": password | |
| } | |
| headers = { | |
| #"Accept": "*/*", | |
| "Cache-Control": "no-cache", | |
| "Accept": "application/json" | |
| } | |
| try: | |
| session = requests.Session() | |
| response = session.get(url, params=params, headers=headers,verify=False) | |
| #print("Content-Type:", response.headers.get("Content-Type")) | |
| if response.status_code == 200: | |
| wh_url = f"http://euwdsw202em01:4660/api/user/v1/users/{usr_id}/warehouses" | |
| wh_response = session.get(wh_url, verify=False) | |
| authorized_wh = "WH1" # Fallback default | |
| if wh_response.status_code == 200: | |
| wh_data = wh_response.json().get("data", []) | |
| if wh_data: | |
| # Logic: Take the first warehouse ID they are assigned to | |
| # Or find the one marked as 'primary' if the API provides it | |
| authorized_wh = wh_data[0].get("wh_id", "WH1") | |
| print(f"Login Success. User {usr_id} assigned to {authorized_wh}") | |
| # Return the session AND the locked warehouse ID | |
| return session, authorized_wh, True | |
| else: | |
| print({"login": "failed", "status_code": response.status_code}) | |
| return None, None, False | |
| except Exception as e: | |
| print({"login": "error", "error": str(e)}) | |
| return None, None, False | |
| #if __name__ == "__main__": | |
| # login() | |