def TAPQuery(query):
    """The __main__ part of the script"""

    tapURL = "http://cadc-ccda.hia-iha.nrc-cnrc.gc.ca/tap/sync"


    ## Some default parameters for that TAP service queries.
    tapParams={'REQUEST': 'doQuery',
               'LANG':    'ADQL',
               'FORMAT':  'votable',
               'QUERY':   query}
    cnt=0
    while True:	
       try:
          print "running query"
          r=urllib2.urlopen(tapURL,urllib.urlencode(tapParams))
          return r
       except urllib2.HTTPError, e:
          cnt+=1
          if e.code!=503:
              sys.stderr.write("# TAP Query got Code: %s Attempt: %d (exiting)\n" % (str(e.code),cnt))
              sys.exit(-1)
          sys.stderr.write("# TAP Query got Code: %s Attempt: %d (sleeping for 10)\n" % (str(e.code),cnt))
          time.sleep(10)