{ "metadata": { "name": "basic authentication" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import urllib2, base64\n", "import json" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "url='https://enlighten.enphaseenergy.com/systems/15610/devices/395315/graph_widget.json?timeframe=recent'\n", "username='rsignell@usgs.gov'\n", "password='4U10PXWU55'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "request = urllib2.Request(url)\n", "base64string = base64.encodestring('%s:%s' % (username, password)).replace('\\n', '')\n", "request.add_header(\"Authorization\", \"Basic %s\" % base64string) \n", "result = urllib2.urlopen(request)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "json=result.read()" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "print(json)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "\n", "
\n", " \n", " \n", " \n", "\n", "Enlighten is compatible with the following browsers: Chrome 5 or higher, Firefox 11 or higher, Internet Explorer 8 or higher, Safari 5 or higher.
\n", "\n", "