Update app.py
Browse files
app.py
CHANGED
@@ -30,17 +30,24 @@ def get_backlinks(api_login, api_key, target_url, filters):
|
|
30 |
st.json(response.json()) # This will display the full JSON response in the Streamlit app
|
31 |
|
32 |
# Check if the response contains 'results' key
|
33 |
-
if response.status_code == 200
|
34 |
-
|
35 |
-
|
36 |
-
if results
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
42 |
else:
|
43 |
-
|
|
|
|
|
|
|
44 |
return None
|
45 |
else:
|
46 |
error_message = response.json().get('status_message', 'No specific error message provided')
|
|
|
30 |
st.json(response.json()) # This will display the full JSON response in the Streamlit app
|
31 |
|
32 |
# Check if the response contains 'results' key
|
33 |
+
if response.status_code == 200:
|
34 |
+
response_data = response.json()
|
35 |
+
|
36 |
+
# Check if 'results' key is in the response
|
37 |
+
if 'results' in response_data:
|
38 |
+
results = response_data['results']
|
39 |
+
if results:
|
40 |
+
# Adjust the following line based on the actual JSON structure
|
41 |
+
df = pd.json_normalize(results)
|
42 |
+
return df
|
43 |
+
else:
|
44 |
+
st.error("Received empty data from API.")
|
45 |
+
return None
|
46 |
else:
|
47 |
+
# Handle other internal status codes here
|
48 |
+
internal_status_code = response_data.get('status_code', None)
|
49 |
+
internal_status_message = response_data.get('status_message', 'No specific message provided')
|
50 |
+
st.error(f"Internal Status Code: {internal_status_code}, Message: {internal_status_message}")
|
51 |
return None
|
52 |
else:
|
53 |
error_message = response.json().get('status_message', 'No specific error message provided')
|