Spaces:
Sleeping
Sleeping
Update app.py
#2
by
DSatishchandra
- opened
app.py
CHANGED
@@ -9,7 +9,7 @@ CLIENT_SECRET = "6F7E9C95CE20CC07FC1EBD39B34909739D99975A0EEB548240926EA0686E428
|
|
9 |
USERNAME = "[email protected]"
|
10 |
PASSWORD = "Vedavathi@04" # Keep this as the password (without the security token)
|
11 |
SECURITY_TOKEN = "qe4His8AcuFJucZz5NBHfGU" # Your Salesforce Security Token
|
12 |
-
TOKEN_URL = "https://login.salesforce.com/services/oauth2/token"
|
13 |
API_VERSION = "v60.0"
|
14 |
|
15 |
# ---------------------- AUTH ----------------------
|
@@ -23,9 +23,13 @@ def get_salesforce_token():
|
|
23 |
"password": PASSWORD + SECURITY_TOKEN # Correctly concatenate password and security token
|
24 |
}
|
25 |
response = requests.post(TOKEN_URL, data=data)
|
|
|
26 |
if response.status_code != 200:
|
27 |
-
|
|
|
|
|
28 |
return None, None
|
|
|
29 |
res = response.json()
|
30 |
return res["access_token"], res["instance_url"]
|
31 |
|
@@ -37,9 +41,11 @@ def fetch_pole_data(instance_url, access_token):
|
|
37 |
query = "SELECT Name, Location_Latitude__c, Location_Longitude__c, Camera_Status__c FROM Pole__c LIMIT 100"
|
38 |
url = f"{instance_url}/services/data/{API_VERSION}/query?q={query}"
|
39 |
response = requests.get(url, headers=headers)
|
|
|
40 |
if response.status_code != 200:
|
41 |
-
st.error("Failed to fetch Pole data")
|
42 |
return pd.DataFrame()
|
|
|
43 |
records = response.json().get("records", [])
|
44 |
df = pd.DataFrame(records)
|
45 |
return df[["Name", "Location_Latitude__c", "Location_Longitude__c", "Camera_Status__c"]]
|
|
|
9 |
USERNAME = "[email protected]"
|
10 |
PASSWORD = "Vedavathi@04" # Keep this as the password (without the security token)
|
11 |
SECURITY_TOKEN = "qe4His8AcuFJucZz5NBHfGU" # Your Salesforce Security Token
|
12 |
+
TOKEN_URL = "https://login.salesforce.com/services/oauth2/token" # For production
|
13 |
API_VERSION = "v60.0"
|
14 |
|
15 |
# ---------------------- AUTH ----------------------
|
|
|
23 |
"password": PASSWORD + SECURITY_TOKEN # Correctly concatenate password and security token
|
24 |
}
|
25 |
response = requests.post(TOKEN_URL, data=data)
|
26 |
+
|
27 |
if response.status_code != 200:
|
28 |
+
# Log detailed error message for better debugging
|
29 |
+
error_message = response.json() if response.status_code != 200 else "No error message"
|
30 |
+
st.error(f"Authentication failed! Status code: {response.status_code}, Message: {error_message}")
|
31 |
return None, None
|
32 |
+
|
33 |
res = response.json()
|
34 |
return res["access_token"], res["instance_url"]
|
35 |
|
|
|
41 |
query = "SELECT Name, Location_Latitude__c, Location_Longitude__c, Camera_Status__c FROM Pole__c LIMIT 100"
|
42 |
url = f"{instance_url}/services/data/{API_VERSION}/query?q={query}"
|
43 |
response = requests.get(url, headers=headers)
|
44 |
+
|
45 |
if response.status_code != 200:
|
46 |
+
st.error(f"Failed to fetch Pole data! Status code: {response.status_code}, Message: {response.json()}")
|
47 |
return pd.DataFrame()
|
48 |
+
|
49 |
records = response.json().get("records", [])
|
50 |
df = pd.DataFrame(records)
|
51 |
return df[["Name", "Location_Latitude__c", "Location_Longitude__c", "Camera_Status__c"]]
|