title: python automatic re-accessing without changing cookie
body: <p>I have a problem with accessing specific web site.<br>
  The Web site automatically redirect to Check Page which is displaying "check your Browser"<br>
  The Check page returns HTTP 503 errors in first time.<br>
  Then web browser(chrome, IE etc) automatically re-access again.<br>
  Finally I can get into web site.</p>
  
  <p>The problem is I want to access to site in Python.
  So I use urllib and urllib2 both.  </p>
  
  <pre><code>u = urllib.open(url)
  print u.read()
  </code></pre>
  
  <p>Same with urllib2, but it doesn't work raising 503 error.<br>
  urllib also get HTTP 503 code but it doesn't raise error.  </p>
  
  <p>So I need to re-access without changing cookie</p>
  
  <pre><code>u = urllib.open(url)
  u = urllib.open(url) ## cookie is changed
  print u.read()
  </code></pre>
  
  <p>Simply I tried to call open function twice. But cookie is changed and it doesn't work<br>
  (Check Page Again)</p>
  
  <p>So I use urllib2 with cooklib</p>
  
  <pre><code>import os.path
  cj = None
  ClientCookie = None
  cookielib = None
  
  import cookielib
  import urllib2
  cj = cookielib.LWPCookieJar()
  
  if os.path.isfile('cookie.lpw'):
      cj.load('cookie.lpw')
  
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  urllib2.install_opener(opener)
  
  theurl = url
  txdata = None
  txheaders = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}
  
  req = urllib2.Request(theurl, txdata, txheaders)
  handle = urllib2.urlopen(req) ## error raised 
  </code></pre>
  
  <p>Error Code Here</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#20&gt;", line 1, in &lt;module&gt;
      handle = urlopen(req)
    File "C:\Python27\lib\urllib2.py", line 127, in urlopen
      return _opener.open(url, data, timeout)
    File "C:\Python27\lib\urllib2.py", line 410, in open
      response = meth(req, response)
    File "C:\Python27\lib\urllib2.py", line 523, in http_response
      'http', request, response, code, msg, hdrs)
    File "C:\Python27\lib\urllib2.py", line 448, in error
      return self._call_chain(*args)
    File "C:\Python27\lib\urllib2.py", line 382, in _call_chain
      result = func(*args)
    File "C:\Python27\lib\urllib2.py", line 531, in http_error_default
      raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
  HTTPError: HTTP Error 503: Service Temporarily Unavailable
  </code></pre>
  
  <p>Simply I want to re-access the site when got HTTP 503 error without change cookies.<br>
  But I don't know how to do it.<br>
  Somebody help me please.</p>