We help IT Professionals succeed at work.

HP Warranty Status Script Needs Fixing

veedar asked
Consider the script (i do not know the author) in the code box called check_hp_warranty.py when run from the Linux command line it used to give the status of an HP computer. For example...

check_hp_warranty.py  -S CN272400X1 -P GG038AAR

Product Model: HP Pavilion a6109n Desktop PC
Serial Number: CN272400X1
Product Number: GG038AAR
Warranty Status: Warranty has expired
Warranty End Date: 2008-02-18

But it no longer works. The script was based on this url...

...but that page no longer exists. The check warranty page is now...

...but it pops up a box asking for "your valuable input". To get around that I embed the Serial and Product name in the url like so...

...that gets me to a page where if I click submit then you see the actual warranty info page.

So I ask two questions is there a way to set tmp_weDest= at the end of the url to something that will automatically click the submit button?

And if so is there then a way to change the script so it works again?

#!/usr/bin/env python
import sys
import re
import urllib
import urllib2
import datetime
import optparse

__version__ = '1.0'

# Nagios exit codes
OK       = 0
SERVICE_URL = "http://h10025.www1.hp.com/ewfrf/wc/weResults"

class Request:

    def __init__(self, serial_no, product_no, country):
        self.country = country
        self.serial_no = serial_no
        self.product_no = product_no

    def encode(self):
        data = {}
        data['tmp_weCountry'] = self.country
        data['tmp_weSerial'] = self.serial_no
        data['tmp_weProduct'] = self.product_no
        ### Extra forms
        data['lc'] = "en"
        data['dlc'] = "en"
        data['cc'] = self.country
        data['tmp_track_link'] = "ot_we/submit/en_us/entitlement/loc:0#"
        return urllib.urlencode(data)

class WarrantyInfo:

    def __init__(self, serial_no, product_no, model,
                 warranty_status, warranty_end):
        self.serial_no = serial_no
        self.product_no = product_no
        self.model = model
        self.warranty_status = warranty_status
        self.warranty_end = warranty_end

    def prettyPrint(self):
        print "Product Model: %s" % self.model
        print "Serial Number: %s" % self.serial_no
        print "Product Number: %s" % self.product_no
        print "Warranty Status: %s" % self.warranty_status
        print "Warranty End Date: %s" % self.warranty_end
        print "Days remaining: %s" % self.getRemain()

    def getRemain(self):
        yyyy, mm, dd = self.warranty_end.split("-")
        end = datetime.date(int(yyyy), int(mm), int(dd))
        remain = end - datetime.date.today()
        if remain.days < 1:
            return 0
            return remain.days

    def minimalPrint(self):
        print "OK: Product Model: %s, Serial Number: %s, Product Number: %s, Status: %s, End: %s, Remain:%s" % \
            (self.model, self.serial_no, self.product_no, self.warranty_status, self.warranty_end, self.getRemain())

def extractInfo(serial_no, product_no, country):

    def getWarrantyStatus(s):
        span = """<span.*?>(.*?)</span>"""
        span_regex = re.compile(span)
        r = span_regex.findall(s)
        if len(r) == 5 or len(r) == 6:
            return r[3]
        return None

    def getWarrantyEndDate(s):
        td = """<td.*?>(.*?)</td>"""
        td_regex = re.compile(td)
        r = td_regex.findall(s)
        if len(r) == 12:
            return r[11].rstrip(" (YYYY-MM-DD)")
        elif len(r) == 15:
            return r[14].rstrip(" (YYYY-MM-DD)")
        return None

    def getModel(s):
        a = """<a.*?>(.*?)</a>"""
        a_regex = re.compile(a)
        #print "lens: %s" % len(s)
        # 7 8 or 9 below (as of 30Sep210 the match changed from 7 to 8) 
        if len(s) == 7 or len(s) == 8 or len(s) == 9:
            # s[6] below is the number of lines on the source page containing <a ... /a> ,i think?
            r = a_regex.findall(s[6])
            #print "lenr: %s" % len(r)
            # 5 below is the line number that has the model info ,i think?
            if len(r) == 5:
                return r[0].lstrip("More troubleshooting for your ")
        return None

    table = r"""(<table.*?</table>)"""
    table_regex = re.compile(table, re.X)

        r = Request(serial_no, product_no, country)
        response = urllib2.urlopen(SERVICE_URL, r.encode())
    except Exception, e:
        print "ERROR: %s" % e

    result = table_regex.findall(response.read())
    success = False
    for r in result:
        if r.__contains__(serial_no) and r.__contains__(product_no):
            status = getWarrantyStatus(r)
            date =  getWarrantyEndDate(r)
            model = getModel(result)
            success = True
            return WarrantyInfo(serial_no,

if __name__ == '__main__':
    parser = optparse.OptionParser(description="Script for checking HP product warranty",
                                   version="%prog Version 1.0")
    parser.add_option("-C", "--country",
                      help=("Product's country code. Defaults to 'us'"))
    parser.add_option("-S", "--serial-no",
                      help=("The item's Serial Number"))
    parser.add_option("-P", "--product-no",
                      help=("The item's Product Number"))
    parser.add_option("-M", "--minimal",
                      help=("Show minimal output"))
    (options, args) = parser.parse_args()
    result = extractInfo(options.serial_no,
    if not result:
        print "ERROR: Product not found, please check serial and product code"
        if options.minimal:

Open in new window

Watch Question

I don't know how this web page works.
Not knowing this makes it difficult to give you the correct answer.

What I assume is following:

have to make an initial get request with the url, that you are using.
As result you will get an html page with a form and a submit button.
What you had probably to di is parse he html code, that you receive.
The intersting part will be betweent the tag <form> and </form>
Could you please post this section of the html, that you receive.
Knowing this contents I can probably tell you which request (probably a POST request) with which values you had to make to get the next page.

Additionally it would be important to know whether the web servers is suing cookies or not.

Just disable cookies in your web browser and try to access the web page manually and do the
 click on 'submit'
f it works, then you know, that no cookies are required.


Thanks gelonida here's the code between <form> and </form>

Note I tried using "tmp_weDest=Submit.click%20%20" but no luck.

Also I tried manually with cookies off and clicking submit worked normally.

--><div class="content_block "><form method="POST" action="weResults" name="entitleinput"><h2 class="">Check your product warranty</h2><div class="content_block textLevelA"><div class="
      "></div><div class="clear"></div><div class="float60pctSeperator"><script type="text/javascript" language="javascript">
          var formArray = [];
          </script><div class="
      "><span style="font-weight: bold;">Manual Warranty Check</span></div><div class="
      ">Please select the country where you would like service (even if you purchased your product in a different country), and enter the serial number and product number below, then click on .Submit..</div><span class="color990000">Please complete the form below. Required fields are denoted with an *.&nbsp;&#8250;</span><br><br><table border="0" cellspacing="0" cellpadding="0"><tr><td valign="top" class="
      "><span class="bold"><label id="countryLabel">Country<span class="color990000bld"> *&nbsp;&#8250;</span></label></span></td><td align="left" width="5"><img src="http://welcome.hp-ww.com/img/s.gif" width="5" height="1" alt=""></td><td valign="top" width="100%" class="
      "><div class="
          "><select id="cc" name="tmp_weCountry"><option value="-1">Select</option><option value="fm">"Micronesia, Federated States of"</option><option value="md">"Moldova, Republic of"</option><option value="af">Afghanistan</option><option value="al">Albania</option><option value="dz">Algeria</option><option value="as">American Samoa</option><option value="ad">Andorra</option><option value="ao">Angola</option><option value="ai">Anguilla</option><option value="ag">Antigua and Barbuda</option><option value="ar">Argentina</option><option value="am">Armenia</option><option value="aw">Aruba</option><option value="au">Australia</option><option value="at">Austria</option><option value="az">Azerbaijan</option><option value="bs">Bahamas</option><option value="bh">Bahrain</option><option value="bd">Bangladesh</option><option value="bb">Barbados</option><option value="by">Belarus</option><option value="be">Belgium</option><option value="bz">Belize</option><option value="bj">Benin</option><option value="bm">Bermuda</option><option value="bt">Bhutan</option><option value="bo">Bolivia</option><option value="ba">Bosnia and Herzegovina</option><option value="bw">Botswana</option><option value="br">Brazil</option><option value="io">British Indian Ocean Territory</option><option value="bn">Brunei Darussalam</option><option value="bg">Bulgaria</option><option value="bf">Burkina Faso</option><option value="bi">Burundi</option><option value="kh">Cambodia</option><option value="cm">Cameroon</option><option value="ca">Canada</option><option value="cv">Cape Verde</option><option value="ky">Cayman Islands</option><option value="cf">Central African Republic</option><option value="td">Chad</option><option value="cl">Chile</option><option value="cn">China</option><option value="cx">Christmas Island</option><option value="cc">Cocos (Keeling) Islands</option><option value="co">Colombia</option><option value="km">Comoros</option><option value="ck">Cook Islands</option><option value="cr">Costa Rica</option><option value="ci">Cote D'ivoire</option><option value="hr">Croatia</option><option value="cy">Cyprus</option><option value="cz">Czech Republic</option><option value="dk">Denmark</option><option value="dj">Djibouti</option><option value="dm">Dominca</option><option value="do">Dominican Republic</option><option value="ec">Ecuador</option><option value="eg">Egypt</option><option value="sv">El Salvador</option><option value="gq">Equatorial Guinea</option><option value="er">Eritrea</option><option value="ee">Estonia</option><option value="et">Ethiopia</option><option value="fk">Falkland Islands (Malvinas)</option><option value="fo">Faroe Islands</option><option value="fj">Fiji</option><option value="fi">Finland</option><option value="fr">France</option><option value="gf">French Guiana</option><option value="pf">French Polynesia</option><option value="tf">French Southern Territories</option><option value="ga">Gabon</option><option value="gm">Gambia</option><option value="ge">Georgia</option><option value="de">Germany</option><option value="gh">Ghana</option><option value="gi">Gibraltar</option><option value="gr">Greece</option><option value="gl">Greenland</option><option value="gd">Grenada</option><option value="gp">Guadeloupe</option><option value="gu">Guam</option><option value="gt">Guatemala</option><option value="gn">Guinea</option><option value="gw">Guinea-Bissau</option><option value="gy">Guyana</option><option value="ht">Haiti</option><option value="hm">Heard Island and Macdonald Island</option><option value="va">Holy See (Vatican City State)</option><option value="hn">Honduras</option><option value="hk">Hong Kong</option><option value="hu">Hungary</option><option value="is">Iceland</option><option value="in">India</option><option value="id">Indonesia</option><option value="iq">Iraq</option><option value="ie">Ireland</option><option value="il">Israel</option><option value="it">Italy</option><option value="jm">Jamaica</option><option value="jp">Japan</option><option value="jo">Jordan</option><option value="kz">Kazakstan</option><option value="ke">
      var oTemp = new Object; oTemp.id = 'cc';
      oTemp.label = 'countryLabel';

        oTemp.required = 'true';
        oTemp.requiredFailureMessage = 'A Country selection is required';

          oTemp.hasValidator = false;


    </script></div></td></tr><tr><td valign="top" nowrap="true" class="
      "><span class="bold"><label id="snLabel">Serial number<span class="color990000bld"> *&nbsp;&#8250;</span></label></span></td><td align="left" width="5"><img src="http://welcome.hp-ww.com/img/s.gif" width="5" height="1" alt=""></td><td valign="top" width="100%" class="
      "><div class="
          "><div><input id="serialnum" maxlength="15" name="tmp_weSerial" size="15" type="text" value="2CE9075KRX"></div><div><script type="text/javascript" language="Javascript">
      var oTemp = new Object; oTemp.id = 'serialnum';
      oTemp.label = 'snLabel';

        oTemp.required = 'true';
        oTemp.requiredFailureMessage = 'serial number is required';

          oTemp.hasValidator = 'true';
          oTemp.validatorType = 'regex';

            oTemp.validatorRegex = '^[a-zA-Z0-9]{10,15}$';

          oTemp.validatorFailureMessage = 'Please enter a valid serial number';


    </script></div><div>e.g. HU265BM18V</div></div></td></tr><tr><td valign="top" nowrap="true" class="
      "><span class="bold"><label id="pnLabel">Product number<span class="color990000bld"> *&nbsp;&#8250;</span></label></span></td><td align="left" width="5"><img src="http://welcome.hp-ww.com/img/s.gif" width="5" height="1" alt=""></td><td valign="top" width="100%" class="
      "><div class="
          "><div><input id="prodName" maxlength="12" name="tmp_weProduct" size="12" type="text" value="NB276UA"></div><div><script type="text/javascript" language="Javascript">
      var oTemp = new Object; oTemp.id = 'prodName';
      oTemp.label = 'pnLabel';

        oTemp.required = 'true';
        oTemp.requiredFailureMessage = 'product number is required';

          oTemp.hasValidator = false;


    </script></div><div>e.g. C8375A</div></div></td></tr></table><div class="rightAligned"><input type="hidden" name="lc" value="en"><input type="hidden" name="dlc" value="en"><input type="hidden" name="cc" value="us"><input type="hidden" name="tmp_weDest" value="Submit.click  "><input type="hidden" name="tmp_track_link" value="ot_we/submit/en_us/entitlement/loc:0"><input type="submit" alt="Submit" title="Submit" id="Continue" class="primButtonEnhanced" value="Submit" onclick="return wfv(document.entitleinput);" onkeypress="return wfv(document.entitleinput);"></div></div><div class="float40pct"><span style="font-weight: bold;">Automatic Product Detection & Warranty Check</span><div class="

      ">This function will detect the product and serial numbers stored electronically on your system(s) that allows you to check your warranty status.</div><div class="
      "><div class="centerAligned"><a href="http://h20614.www2.hp.com/ediags/gmd/welcome.aspx?lc=en&cc=us&product=&tmp_weDest=Submit.click%20%20" title="Start Detection" class="primButtonEnhanced">Start Detection</a></div></div><a href="http://h20614.www2.hp.com/ediags/gmd/about.aspx?lc=en&cc=us&product=&tmp_weDest=Submit.click%20%20">About automatic product detection&nbsp;&#8250;</a></div><div class="clear"></div></div><div class="clear"></div></form></div></div><div id="right_rail"><h4 class="first_section_header">How Do I Find My Product Number and Serial Number?</h4><div class="blockDivider_rrail"></div><div><div class="section"><div style="margin: 1em 0;">The <strong>Serial Number</strong>

Open in new window


Well this web site is using some javascript and is not that easily readble.

Do you have Firefox?

If yes, then I would install the plugin Firebug. (Excellent plugin to analyze web pages, seen what data is posteds, etc.)

It allwows you to trace the web traffic and to see exactly what values have been posted in a post / get request.

So install firebug;
- restart firefox
- click on the firebug icon
- click on the 'Net' tab and enable select, that you want to view all the network traffic.
- Go to the Hp web site
Do once more the steps you want to do manually and search for a 'POST" request in your 'Net' log'

select the 'Post' tab to see exactly what data has been posted.
This is basically, what should be in your Request.encode() method (The method creating the data to be posted)