title: Authorization error when parsing data from router
body: <p>I want to scrap the data from my router for some home automation, but im facing some trouble I cannot solve/crack.</p>
  
  <p>I have managed to successfully login into the router, but when accessing the data with python script (opening links in router web interface) I recieve an error saying: You have no authority to access this router!</p>
  
  <p>If I manually copy and paste url that python script is accessing into browser (with cookies set), the response is the same. But if i click the buttons inside router web interface i get no "authority" complains. Any ideas how to fix this?</p>
  
  <p>here is the script:</p>
  
  <pre><code>import re
  import mechanize
  import cookielib
  
  br = mechanize.Browser()
  
  cookies = cookielib.LWPCookieJar()
  br.set_cookiejar(cookies)
  #they "encrypt" the username and password and store it into the cookie. I stole this value from javascript in runtime.
  br.addheaders = [('Cookie','Authorization=Basic YWRtaW46MjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzM=;')] 
  #open connection to the router address
  br.open('http://192.168.1.1/')
  #the only form is "login" form (which we dont have to fill up, because we already have the cookie)
  br.select_form(nr=0) 
  br.form.enctype = "application/x-www-form-urlencoded"
  br.submit() 
  
  #then the router returns redirect script, so we have to parse it (get the url).
  redirect_url = re.search('(http:\/\/[^"]+)',br.response().read()).group(1)
  token = re.search("1\/([A-Z]+)\/",redirect_url).group(1) #url always has a random token inside (some kind of security?)
  
  #So with this url I should be able to navigate to page containing list of DHCP clients
  br.open("http://192.168.1.1/"+token+"/userRpm/AssignedIpAddrListRpm.htm")
  
  print(br.response().read()) #But response contains html saying "You have no authority to access this router!".
  </code></pre>