In [1]:
import urllib2, base64
import json

In [ ]:
url='https://enlighten.enphaseenergy.com/systems/15610/devices/395315/graph_widget.json?timeframe=recent'
username='rsignell@usgs.gov'
password='4U10PXWU55'

In [ ]:


In [ ]:
request = urllib2.Request(url)
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)   
result = urllib2.urlopen(request)

In [10]:
json=result.read()

In [12]:
print(json)


<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=IE8">
    <meta charset="UTF-8">
    <meta name="csrf-param" content="authenticity_token"/>
<meta name="csrf-token" content="sTFo2xxhWX&#47;FMSa49ws9ZWjXrcdA3JV+3NKrRw&#47;6H7s="/>
    <title>Enphase Energy - Enlighten | Sign in to Enlighten</title>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" >
    <link rel="apple-touch-icon-precomposed" href="/images/mobile/enphase_touch-icon-precomposed.png"/>
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/images/mobile/enphase_touch-ipad-precomposed.png" />
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="t/images/mobile/enphase_touch-iphone4-precomposed.png" />
    <meta name="description" content="Enphase Enlighten -- the world&#x27;s most advanced solar monitoring tool.">
    <meta name="format-detection" content="telephone=no" />
    <!--[if (!IE)|(gte IE 8)]><!-->
<link href="https://assets1.enphaseenergy.com/assets/e3_common-datauri.css?1366169259" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="https://assets1.enphaseenergy.com/assets/e3_common.css?1366169259" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
    <!--[if (!IE)|(gte IE 8)]><!-->
<link href="https://assets1.enphaseenergy.com/assets/public-datauri.css?1366169259" media="screen" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="https://assets1.enphaseenergy.com/assets/public.css?1366169259" media="screen" rel="stylesheet" type="text/css" />
<![endif]-->
    <!--[if (!IE)|(gte IE 8)]><!-->
<link href="https://assets1.enphaseenergy.com/assets/e3_print-datauri.css?1349151987" media="print" rel="stylesheet" type="text/css" />
<!--<![endif]-->
<!--[if lte IE 7]>
<link href="https://assets1.enphaseenergy.com/assets/e3_print.css?1349151987" media="print" rel="stylesheet" type="text/css" />
<![endif]-->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <!--[if lt IE 9]>
        <link rel="stylesheet" href="/stylesheets/e3/e3_ie8.css" media="screen" type="text/css" />
        <script type="text/javascript" src="/javascripts/e3_ie_css3-mediaqueries.js"></script>
    <![endif]-->
    <!--[if lt IE 8]>
        <script type="text/javascript" src="/javascripts/e3_ie7.js"></script>
    <![endif]-->
    <!--[if gte IE 9]>
        <link rel="stylesheet" href="/stylesheets/e3/e3_ie9.css" media="screen" type="text/css" />
    <![endif]-->
    
  <script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script></head>
  <body>
    
        

<div id='header_container'>
  <div id='header'>
        <a href="/login" class="enl_logo" id="left_logo"></a>
    
    <div id='user_display'>
      <div  id="nav_account" class="user_link flyout_init">
        <div class="arrow_down"><span class="navbar">Language</span></div>

        <div id="account_flyout" >

          <ul id="language_info">
      <li><a href="/?locale=en-US" class="lang_active selected">English</a></li>
      <li><a href="/?locale=fr" class="">Français</a></li>
      <li><a href="/?locale=it" class="">Italiano</a></li>
</ul>
          <ul id="user_logout" class="link_group">
            <li></li></ul>
        </div>
      </div>
    </div>
  </div>
</div>


        <div class="page"></div>
        <div class='page'>
        <div class="page" id="login">
    <div id="marketing_img">
      <div id='public-system-content'>Want to see Enphase in action? <a href='/public_systems'>View public systems</a></div>
    </div>
    <form accept-charset="UTF-8" action="/login/login" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="sTFo2xxhWX/FMSa49ws9ZWjXrcdA3JV+3NKrRw/6H7s=" /></div>
    <div id='login_box_container'>
    

<!--[form:user]-->
<label for="user_email">Email:</label>
<input autocorrect="on" class="login_text_field" id="user_email" name="user[email]" size="30" type="text" />
<label for="user_password">Password:</label><input autocorrect="off" class="login_text_field" id="user_password" name="user[password]" onkeypress="capLock(event, false)" size="30" type="password" />
<div id="caps_lock_warning" class="ui-state-error ui-corner-all"><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>Caps Lock is on</div>
<!--[eoform:user]-->


    <p id='forgot_password'><a href="/forgot_password">Forgot your password?</a></p>
    <label for="submit" class="butn"><input id="submit" name="commit" type="submit" value="Sign In" /></label>
    <p id="new_user">Installing your first Enphase system? <a href='/users/new'>Sign up for Enlighten</a></p>
    </div>
</form></div>
<div class="clear"></div>
<p id="recommended-browsers">Enlighten is compatible with the following browsers: Chrome 5 or higher, Firefox 11 or higher, Internet Explorer 8 or higher, Safari 5 or higher.</p>
<script type="text/javascript">
$(document).ready(function() {
    $('#user_email').focus();
    $("#submit").button();
    $("#register").button();
});
</script>
        </div><div class='clear'></div>
        <div id='footer_container'>
  <footer id='footer'>
    <a href="http://enphase.com/" class="img" id="enphase_logo" target="blank" title="Visit the Enphase Energy website"></a>
    <section id='copyright'>
      &copy;2008-2013 Enphase Energy Inc. All rights reserved. <a href="http://enphase.com/privacy" target="blank">Privacy</a> | <a href="http://enphase.com/terms" target="blank">Terms</a>
      | <a href="http://community.enphaseenergy.com" target="blank">Community</a>
    </section>
  </footer>

  
  <script type="text/javascript">
  var _gaq = _gaq || [];
  setTimeout(function() {_gaq.push(['_setAccount', 'UA-2434165-3'])},0);
  setTimeout(function() {_gaq.push(['_trackPageview'])},0);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
  
</div>


    <script src="https://assets1.enphaseenergy.com/assets/e3_basic.js?1366169259" type="text/javascript"></script>
    <script type="text/javascript">
     $(function() {
       I18n.defaultLocale = 'en-US';
       I18n.locale = "en-US";
       I18n.fallbacks = true;
     });
    </script>
        <script src="https://assets1.enphaseenergy.com/javascripts/views/login.js?1366169280" type="text/javascript"></script>

  <script type="text/javascript">if (!NREUMQ.f) { NREUMQ.f=function() {
NREUMQ.push(["load",new Date().getTime()]);
var e=document.createElement("script");
e.type="text/javascript";
e.src=(("http:"===document.location.protocol)?"http:":"https:") + "//" +
  "d1ros97qkrwjf5.cloudfront.net/42/eum/rum.js";
document.body.appendChild(e);
if(NREUMQ.a)NREUMQ.a();
};
NREUMQ.a=window.onload;window.onload=NREUMQ.f;
};
NREUMQ.push(["nrfj","beacon-1.newrelic.com","dec8e4c9b0","267719","JloPTUNYCFRUQU4JWgJcDxZYWQBdSQ==",0,18,new Date().getTime(),"","","","",""]);</script></body>
</html>


In [3]:
print result


<addinfourl at 39832752 whose fp = <socket._fileobject object at 0x2d636d0>>

In [4]:
try:
    urllib2.urlopen(urllib2.Request(url))
except urllib2.HTTPError, e:
    print e.headers
    print e.headers.has_key('WWW-Authenticate')

In [5]:
request


Out[5]:
<urllib2.Request instance at 0x2e7e3b0>

In [ ]: