Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
I wrote this because I wanted to get the JSON data from OpenWRT's status page and use it elsewhere. Fill out the user name and password, sorry it's a bit hacky but I'm rolling it into other stuff and this is a minimum implementation.
import requests
import re
import urllib2
url = 'http://openwrt/cgi-bin/luci/'
data = {'luci_username': 'root', 'luci_password': 'password'}
r =, data=data, allow_redirects=True)
cookie = r.request.headers['Cookie']
m ='sysauth=(.*)', cookie, re.IGNORECASE)
sysauth =
m ='stok=(.*?)/', r.content, re.IGNORECASE)
stok =
statusurl = url+';stok=' + stok + '?status=1&_=0.0121'
r = urllib2.Request(statusurl)
r.add_header('Cookie', 'sysauth='+sysauth)
resp = urllib2.urlopen(r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.