joshuadunlop commited on
Commit
b95b7b7
·
verified ·
1 Parent(s): adc823d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -36,21 +36,30 @@ def get_backlinks(api_login, api_key, target_url, filters):
36
  st.text(f"Response Body: <Not a JSON response>\nError: {e}")
37
 
38
  # Check if the response contains 'results' key and handle the JSON structure appropriately
39
- if response.status_code == 200 and 'results' in response_json:
40
- results = response_json['results']
41
- if results:
42
- # Check if the results actually contain the backlink data you expect
43
- st.text(f"Results: {results}") # Debugging line to show the results structure
44
-
45
- # If the structure is as expected, convert to DataFrame
46
- df = pd.json_normalize(results)
47
- return df
 
 
 
 
 
 
 
 
 
48
  else:
49
- st.error("Received empty data from API.")
50
  return None
51
  else:
52
- # Handle API errors
53
- st.error(f"Error: Code: {response.status_code} Message: {response_json.get('status_message', 'No specific error message provided')}")
54
  return None
55
 
56
  def convert_df_to_csv(df):
 
36
  st.text(f"Response Body: <Not a JSON response>\nError: {e}")
37
 
38
  # Check if the response contains 'results' key and handle the JSON structure appropriately
39
+ if response.status_code == 200:
40
+ response_data = response.json()
41
+
42
+ # Debugging: Print out the keys of the response_data
43
+ st.text(f"Keys in response JSON: {list(response_data.keys())}")
44
+
45
+ if 'results' in response_data:
46
+ results = response_data['results']
47
+ if results:
48
+ # Debugging: print the first few items to inspect the structure
49
+ st.text(f"First few results: {results[:5]}") # assuming results is a list
50
+
51
+ # Convert to DataFrame
52
+ df = pd.json_normalize(results)
53
+ return df
54
+ else:
55
+ st.error("Received empty 'results' from API.")
56
+ return None
57
  else:
58
+ st.error(f"No 'results' key in response JSON. Full response: {response_data}")
59
  return None
60
  else:
61
+ error_message = response.json().get('status_message', 'No specific error message provided')
62
+ st.error(f"Error: Code: {response.status_code} Message: {error_message}")
63
  return None
64
 
65
  def convert_df_to_csv(df):