title: Getting KeyError: 0 when executing the Python script
body: <p>The problem is when I am running the script I am getting the following error:</p>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "test1.py", line 16, in
    
        output.writerow(data[0].keys()) KeyError: 0</p>
  </blockquote>
  
  <p>Following is the python code:</p>
  
  <pre><code>import csv, json, sys
  
  if sys.argv[1] is not None and sys.argv[2] is not None:
      fileInput = sys.argv[1]
      fileOutput = sys.argv[2]
  
      inputFile = open(fileInput)
      outputFile = open(fileOutput, 'w')
      data = json.load(inputFile)
      inputFile.close()
  
      output = csv.writer(outputFile)
  
      output.writerow(data[0].keys())
  
      for row in data:
          output.writerow(row.values())
  </code></pre>
  
  <p>Formatted JSON data : </p>
  
  <pre><code>{
      "response": [
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T11:20:37",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 1,
              "raw_message": "A sinking pound, resignations by the bucketful railroading through a so-called agreement nobody wants. For the good of the country Mrs. May 'go and go now'.",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T11:20:37",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-233509073ed3432027d48b1a83f5fbd2/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-233509073ed3432027d48b1a83f5fbd2",
                  "url": "",
                  "id": "250728493",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-233509073ed3432027d48b1a83f5fbd2.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-233509073ed3432027d48b1a83f5fbd2.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-233509073ed3432027d48b1a83f5fbd2.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-05-03T10:40:52",
                  "disable3rdPartyTrackers": true,
                  "name": "baggiebuoy"
              },
              "parent": null,
              "isFlagged": false,
              "likes": 1,
              "id": "4196155749",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;A sinking pound, resignations by the bucketful railroading through a so-called agreement nobody wants. For the good of the country Mrs. May 'go and go now'.&lt;/p&gt;",
              "isEdited": true,
              "isApproved": true
          },
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T10:37:59",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 0,
              "raw_message": "This could be heaven, or this could be hell.",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T10:37:59",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-29e1c59be16c852670e3be302e8c303b/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-29e1c59be16c852670e3be302e8c303b",
                  "url": "",
                  "id": "250739494",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-29e1c59be16c852670e3be302e8c303b.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-29e1c59be16c852670e3be302e8c303b.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-29e1c59be16c852670e3be302e8c303b.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-05-03T13:01:02",
                  "disable3rdPartyTrackers": false,
                  "name": "Mordecai"
              },
              "parent": 4196013534,
              "isFlagged": false,
              "likes": 0,
              "id": "4196048572",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;This could be heaven, or this could be hell.&lt;/p&gt;",
              "isEdited": false,
              "isApproved": true
          },
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T10:36:50",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 0,
              "raw_message": "The crappest of crap deals.\nWill never get through Parliament.\n\nYou are the weakest link May, goodbye.",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T10:36:50",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-29e1c59be16c852670e3be302e8c303b/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-29e1c59be16c852670e3be302e8c303b",
                  "url": "",
                  "id": "250739494",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-29e1c59be16c852670e3be302e8c303b.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-29e1c59be16c852670e3be302e8c303b.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-29e1c59be16c852670e3be302e8c303b.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-05-03T13:01:02",
                  "disable3rdPartyTrackers": false,
                  "name": "Mordecai"
              },
              "parent": null,
              "isFlagged": false,
              "likes": 0,
              "id": "4196044068",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;The crappest of crap deals.&lt;br&gt;Will never get through Parliament.&lt;/p&gt;&lt;p&gt;You are the weakest link May, goodbye.&lt;/p&gt;",
              "isEdited": false,
              "isApproved": true
          },
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T10:28:13",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 0,
              "raw_message": "We are all just prisoners here of our own device. \ud83d\ude01",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T10:28:13",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-42ba513c42a0fd6558aa44b1de658140/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-42ba513c42a0fd6558aa44b1de658140",
                  "url": "",
                  "id": "274657487",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-42ba513c42a0fd6558aa44b1de658140.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-42ba513c42a0fd6558aa44b1de658140.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-42ba513c42a0fd6558aa44b1de658140.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-12-20T16:45:10",
                  "disable3rdPartyTrackers": true,
                  "name": "chaffwolf"
              },
              "parent": 4195981074,
              "isFlagged": false,
              "likes": 0,
              "id": "4196013534",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;We are all just prisoners here of our own device. \ud83d\ude01&lt;/p&gt;",
              "isEdited": false,
              "isApproved": true
          },
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T10:27:03",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 0,
              "raw_message": "Should be no deal end off.\nNobody could possibly be the winner so it's simple leave and that's it .\nTheir will always be wannabes who think they can do better in it for only their own powers not for the general country or the people of it .,",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T10:27:03",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-90ecce8d5dad4396f681182cb470872c/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-90ecce8d5dad4396f681182cb470872c",
                  "url": "",
                  "id": "251694793",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-90ecce8d5dad4396f681182cb470872c.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-90ecce8d5dad4396f681182cb470872c.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-90ecce8d5dad4396f681182cb470872c.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-05-12T20:20:43",
                  "disable3rdPartyTrackers": true,
                  "name": "wanderer in eire"
              },
              "parent": null,
              "isFlagged": false,
              "likes": 0,
              "id": "4196012501",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;Should be no deal end off.&lt;br&gt;Nobody could possibly be the winner so it's simple leave and that's it .&lt;br&gt;Their will always be wannabes who think they can do better in it for only their own powers not for the general country or the people of it .,&lt;/p&gt;",
              "isEdited": false,
              "isApproved": true
          },
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T10:26:42",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 0,
              "raw_message": "Damned if she does, damned if she doesn't. All for a cause she does not believe in.\nShe will go down in history whatever happens. \nThe question is: who better to lead the country at such an important juncture??\nAnswers on a postcard!",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T10:26:42",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-42ba513c42a0fd6558aa44b1de658140/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-42ba513c42a0fd6558aa44b1de658140",
                  "url": "",
                  "id": "274657487",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-42ba513c42a0fd6558aa44b1de658140.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-42ba513c42a0fd6558aa44b1de658140.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-42ba513c42a0fd6558aa44b1de658140.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-12-20T16:45:10",
                  "disable3rdPartyTrackers": true,
                  "name": "chaffwolf"
              },
              "parent": null,
              "isFlagged": false,
              "likes": 0,
              "id": "4196012237",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;Damned if she does, damned if she doesn't. All for a cause she does not believe in.&lt;br&gt;She will go down in history whatever happens. &lt;br&gt;The question is: who better to lead the country at such an important juncture??&lt;br&gt;Answers on a postcard!&lt;/p&gt;",
              "isEdited": false,
              "isApproved": true
          },
          {
              "thread": "7046384220",
              "numReports": 0,
              "editableUntil": "2018-11-22T09:50:32",
              "sb": false,
              "media": [],
              "moderationLabels": [],
              "isSpam": false,
              "isHighlighted": false,
              "dislikes": 0,
              "points": 0,
              "raw_message": "Theresa May is using The Eagles Hotel California lyrics as the inspiration for her Brexit plan.\n\nYou can check out any time you like, but you can never leave.",
              "forum": "expressandstar",
              "createdAt": "2018-11-15T09:50:32",
              "canVote": false,
              "author": {
                  "profileUrl": "https://disqus.com/by/mnaid-e82a88d937e60267fd2c866b01131ada/",
                  "isPrivate": false,
                  "isPrimary": true,
                  "about": "",
                  "username": "mnaid-e82a88d937e60267fd2c866b01131ada",
                  "url": "",
                  "id": "250727584",
                  "isAnonymous": false,
                  "avatar": {
                      "permalink": "https://disqus.com/api/users/avatars/mnaid-e82a88d937e60267fd2c866b01131ada.jpg",
                      "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png",
                      "small": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-e82a88d937e60267fd2c866b01131ada.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar32.png"
                      },
                      "large": {
                          "permalink": "https://disqus.com/api/users/avatars/mnaid-e82a88d937e60267fd2c866b01131ada.jpg",
                          "cache": "//a.disquscdn.com/1541535443/images/noavatar92.png"
                      },
                      "isCustom": false
                  },
                  "location": "",
                  "isPowerContributor": false,
                  "signedUrl": "",
                  "joinedAt": "2017-05-03T10:27:23",
                  "disable3rdPartyTrackers": false,
                  "name": "Olly the cat"
              },
              "parent": null,
              "isFlagged": false,
              "likes": 0,
              "id": "4195981074",
              "isDeletedByAuthor": false,
              "isDeleted": false,
              "message": "&lt;p&gt;Theresa May is using The Eagles Hotel California lyrics as the inspiration for her Brexit plan.&lt;/p&gt;&lt;p&gt;You can check out any time you like, but you can never leave.&lt;/p&gt;",
              "isEdited": false,
              "isApproved": true
          }
      ],
      "code": 0,
      "cursor": {
          "more": false,
          "total": null,
          "prev": null,
          "hasNext": false,
          "next": "1542275432008325:1:0",
          "id": "1542275432008325:1:0",
          "hasPrev": false
      }
  }
  </code></pre>
  
  <p>My main project is taking data from the JSON file and making a relational database with the data.</p>