Hi this is my code for chuck norris joke and I am getting error while submitting my csv file which is correct.
Please can someone help me in identifying the problem.
#‘http://api.icndb.com/jokes/1’
import requests
import json
with open(“ID.csv”,“r”) as file:
ids=(file.readlines())
ids=[int(value[:-1]) for value in ids[1:]]
# print(ids)
with open(“output.csv”,“w”) as file:
file.write(“ID,Joke\n”)
result=""
for id in ids[1:]:
joke_url=f’http://api.icndb.com/jokes/{id}’
response=requests.get(joke_url)
data=json.loads(response.content)
result+="{},".format(id)+data[‘value’][‘joke’]+"\n"
print(result)
# result=result[:-1]
print(result)
file.write(result)