title: Why does my code not write the data it receives from the build_info function to the json file?
body: <pre class="lang-py prettyprint-override"><code>api = shodan.Shodan(api_key)
  
  query = 'MongoDB Server Information \n{ &quot;process&quot;: &quot;mongod&quot; port:27017'
  
  build_info_arr = []
  
  try:
      results = api.search(query)
      print('Total Results: %s\n' % results['total'])
  
      for result in results['matches']:
          if &quot;Authentication partially enabled&quot; not in result['data']:
              print('IP: {}'.format(result['ip_str']))
              ip: str = format(result['ip_str'])
              collections = mongodb_search.build_info(ip)
  
              if collections:
                  data = json.loads(collections)
                  for build_infos in data.items():
                      build_info_arr.append(build_infos)
  
  except shodan.APIError as e:
      print('Error: {}'.format(e))
  
  with open('./test.json', &quot;wt&quot;) as jsonfile:
      jsonfile.write(json.dumps(build_info_arr, indent=4, sort_keys=False))
  </code></pre>
  <p>My build_info function is here:</p>
  <pre class="lang-py prettyprint-override"><code>def build_info(ip):
      try:
          client = pymongo.MongoClient(ip, 27017, maxPoolSize=10)
          data = ''
          for build_info in client.db.command({'buildInfo': 1}):
              data += str(json.dumps(build_info))
              file = json.loads(data)
              return file
      except:
          print('Error: Cannot retrieve buildinfo.')
  </code></pre>