TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
kaushik guru
NA
252
30.8k
how to save api output json as csv file
Sep 21 2020 11:24 PM
I have an 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"]])
return{"sub_start_date_end_date":final}
when executing this end point I am getting the following error list' object has no attribute 'read'
Kindly guide
Reply
Answers (
3
)
How to run a python script in every 5 min using scheduler in windows?
Unable to pass variable from payload to url in python