title: Flickr API script stops when collecting data python
body: <p>I want to collect photos' xmls files from Flickr but my script stops frequently where it collect number of images then stop collecting which time consuming and I could not fix the error where I have to check frequently to re collect the data.
  Can any one highlight the bug in my code or what I should do?</p>
  
  <pre><code>    import flickrapi
      import os
      import sys
      import shutil
      import socket
      import urllib2
      import urllib
      import codecs
      import re
      import socket
      from xml.etree.ElementTree import ElementTree
      import xml.etree.ElementTree as ET
      import httplib
      import numpy as np
      import glob
      import random
      from flickrapi.tokencache import LockingTokenCache
  
  
      httplib.HTTPConnection._http_vsn= 10
      httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0'
      api_key = '...........'
      api_secret='........'
      flickr=flickrapi.FlickrAPI(api_key,api_secret)
  
  
      print(sys.argv)
      if len(sys.argv) == 3:
        print( "Reading data  " + (sys.argv[1]))
        query_file_name = sys.argv[1] 
        startind = int(sys.argv[1]);
        endind = int(sys.argv[2])
      else:
        print('Number of arguments=%d,program terminated')%(len(sys.argv)-1)
        sys.exit (1)
     new='path to load files'
     head='path to save images'    
  
     users_list=open(new+'imgs_list.txt','r')
     e=users_list.readlines()
     f=[s.replace('\n','')for s in e]
     print(len(f))
     users_list.close()
     num=0
     i=startind
  
     while i&lt;=endind:
        try:
            imgid=f[i]
            imgid=imgid.strip('\n')
            num+=1
            photo_info=flickr.photos_getInfo(photo_id=imgid)
            photo_info=ElementTree(photo_info)
            img_info=(head+('/%s.xml'%(imgid)))
            photo_info.write(img_info)
            print(imgid,num,i)
  
        except KeyboardInterrupt:
            print('keyboard exception while querying for images, exiting\n')
            raise
  
        except:
            print('error')
            e=sys.exc_info()
            print(e)
            print('missed img info',imgid)
           missed_data=open(new+'/missed_photos.txt','a')
           missed_data.write(imgid+'\n')
           missed_data.close()
           pass
  
        i+=1 
  </code></pre>