watchforstock / evohome-client

Python client to access the Evohome web service
Apache License 2.0
88 stars 52 forks source link

Handle site failure #1

Closed fullTalgoRythm closed 10 years ago

fullTalgoRythm commented 10 years ago

I've been using your client to update Domoticz which was working great until this morning. I had to do a little digging to find out why but it just turns out the site was down. I'd only just started using it so I thought it could be something else. It would be nice if there was some more error handling to help understand what is happening.

Typical error...

  File "evohome-client/evohomeclient2/__init__.py", line 13, in __init__
    self._login()
  File "evohome-client/evohomeclient2/__init__.py", line 43, in _login
    self.access_token = self._convert(r.text)['access_token']
  File "evohome-client/evohomeclient2/__init__.py", line 16, in _convert
    return json.loads(self.reader(object)[0])
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)          

Obviously it turns out object doesn't contain valid json which is why it's throwing a fit...

Exert of the HTML in object....

        <script type="text/javascript">
            jQuery(document).ready(function() {
                jQuery('#English').click(function() {
                    jQuery('#ConstructionHeader').html("Website Offline");
                    jQuery('#ConstructionText').html("Thank you for using Honeywellâs Total Connect Comfort System.  The site is temporarily not in service during maintenance.  We expect to be online again between 2-6 AM central time.  We are sorry for any inconvenience this has caused.  Please check back.");
                });
                jQuery('#French').click(function() {
                    jQuery('#ConstructionHeader').html("Site Web hors ligne");
                    jQuery('#ConstructionText').html("Merci d'utiliser le système « Total Connect Comfort » de Honeywell. Le site est temporairement hors service pendant l'entretien. Nous nous attendons à être de nouveau en ligne entre le 1-5h, heure du Centre. Nous sommes désolés pour tout inconvénient que cela peut causé.  Sâil vous plaît réessayer plus tard.");
                });

            });
        </script>

There was an alternate error (sorry lost the traceback) the html looked like....

<title>Runtime Error</title>
        <meta name="viewport" content="width=device-width" />
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
         @media screen and (max-width: 639px) {
          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
         }
         @media screen and (max-width: 479px) {
          pre { width: 280px; }
         }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/TotalConnectComfort/Auth' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Runtime Error</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated.
            <br><br>

    </body>

May handle the exception, print object and return an error code so we can do respond?

Also I understand there was another site so I don't know if it would be possible to have a site list and try both

watchforstock commented 10 years ago

Another contributor has improved the handling of HTTP errors so hopefully you'll find this better now

fullTalgoRythm commented 9 years ago

Thanks I'll have a look. The client seems to be working well.