I am passing an id value to a API url to get JSON response, but getting only one response and rest all are throwing 500 errors. I collect the ids in a list and pass the id to API URL as a parameter in a while loop to extract the data.
###Get id in a variable##
df_filter=spark.sql("""select distinct ID from filter_view""")
rdd = df_filter.rdd
listOfRows = rdd.collect()
counter = 0
##total_results = []
while counter < len(listOfRows):
url += '?ids=' + listOfRows[counter].ID
response = requests.get(url,headers=headers)
if response.status_code == 200:
json_response = response.json()
##total_results.append(json_response)
df2 = pd.json_normalize(json_response, record_path=['entities'])
display(df2)
else:
print("Error: HTTP status code " + str(response.status_code))
counter +=1
I am getting output for only one ID and rest all end with 500 errors.
Desired output:
ID---ItemID--Details
1 100 text
1 101 text
2 200 text
2 300 text
3 400 sometext
3 500 sometext
Output I am getting:
ID---ItemID--Details
1 100 text
1 101 text
Error: HTTP status code 500
Error: HTTP status code 500
Error: HTTP status code 500
Error: HTTP status code 500
Error: HTTP status code 500
Error: HTTP status code 500