kaushik guru kaushik guru 1.9k934.6k how to save api output json as csv file

i have a api output as follows

  "sub_start_date_end_date": [   
      "account_id": "10996fd6-a708-4d70-b65e-50620d8fbbdf",     
      "country": "'USA'",
      "end_date": "Fri, 03 Sep 2021 00:00:00 GMT",       
      "start_date": "Thu, 03 Sep 2020 00:00:00 GMT"

i need to save it as create and save it as a csv file

@final.route('/start_date-end_datess', methods=['GET'])

def subscription_datess():
  subscription_id = request.args.get('subscription_id') 
  email = request.args.get('email')
  update_query = '''
some query            ''' 
  result = db.session.execute(text(update_query), {'a':email})
  final = [dict(i) for i in result] 
  excel = json.load(final) 
  files = csv.writer(open("test.csv", "wb+")) 
  files.writerow(["account_id", "country", "end_date", "start_date"]) 

  for excel in excel:     
    files.writerow([excel["account_id"], excel["country"], excel["end_date"], excel["start_date"]]) 


when executing this end point i am getting the following error list’ object has no attribute 'read’

Kindly guide

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

This is particularly important with Python code as it is whitespace-sensitive. If you use strange formatting with large amounts of extra whitespace, it makes it difficult for someone trying to help to copy your code (or at the very least, you are likely to get answers saying that it isn’t working because you have extra spaces, when in fact the whitespace was correct before you copy pasted it in to your post)