title: Trying to make multiple url requests in python, but response only contains one
body: <p>I'm trying to write a Python script that will retrieve 18 sets of JSON data and write them to a single file that I can use for a D3 project. I've only been teaching myself Python for a week, so I'm sure I'm messing this up in some simple way. I would really appreciate help finding my mistakes. Here's the script so far.</p>
  
  <pre><code># Import libraries.
  import requests
  import json
  
  hucs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18];
  for huc in hucs:
  # create request as json, dynamically altering the url to retrieve one HUC at a time.
      if(huc &lt; 10):
          data = requests.get('http://waterservices.usgs.gov/nwis/iv/?format=json&amp;indent=on&amp;huc=0{}&amp;startDT=2015-05-22&amp;endDT=2015-05-22&amp;parameterCd=00060&amp;siteType=OC,OC-CO,ES,LK,ST,ST-CA,ST-DCH,ST-TS'.format(huc), stream=True).json()  
      else:
          data = requests.get('http://waterservices.usgs.gov/nwis/iv/?format=json&amp;indent=on&amp;huc={}&amp;startDT=2015-05-22&amp;endDT=2015-05-22&amp;parameterCd=00060&amp;siteType=OC,OC-CO,ES,LK,ST,ST-CA,ST-DCH,ST-TS'.format(huc), stream=True).json()
  
      # access timeSeries
      time_series = data['value']['timeSeries']
  
      # using open, create a file called data.json which we'll refer to as "output" in the code below
      with open('data/data.json', 'wb') as output:
          # create a single root element.
          root = bytes('{"time_series": {', 'UTF-8')
      # create counter. this is used to add the 'root' element during the first write, and to get rid of an extra comma after latitude in the final iteration.
          counter = 0
      # for every object in the time series
          for number in time_series:
              counter+=1
      # if the site has recorded values
              if(len(number['values'][0]['value']) &gt; 0): 
      # pull out the data we want
                  json_data = bytes('"site": { "properties": { "usgs_name": ' + '"' + number['name'] + '",' + \
                  '"site_name": ' + '"' + number['sourceInfo']['siteName'] + '",' + \
                  '"huc": "{}"'.format(number['sourceInfo']['siteCode'][0]['value']) + ',' + \
                  '"streamflow": ' + '"' + number['values'][0]['value'][0]['value'] + '",' + \
                  '"dateTime": ' + '"' + number['values'][0]['value'][0]['dateTime'] + '",' + \
                  '"longitude": "{}"'.format(number['sourceInfo']['geoLocation']['geogLocation']['longitude']) + ',', 'UTF-8')
  
                  if counter &lt; len(time_series) :
                      json_data = json_data + bytes('"latitude": "{}"'.format(number['sourceInfo']['geoLocation']['geogLocation']['latitude']) + '}},', 'UTF-8')
                  else:
                      json_data = json_data + bytes('"latitude": "{}"'.format(number['sourceInfo']['geoLocation']['geogLocation']['latitude']) + '}}', 'UTF-8')
      # if it's the first iteration, prepend the 'root' of the json heirarchy     
                  if(counter==1):
                      output.write(root + json_data)
                  else:
                      output.write(json_data)
      # close the json object             
          output.write(bytes('}}', 'UTF-8'))
  </code></pre>