GijsTimmers / kotnetcli

An easy automated way to log in on Kotnet.
GNU General Public License v3.0
5 stars 4 forks source link

Throw an exception or error if RC code cannot be found in html response #86

Open jovanbulck opened 8 years ago

jovanbulck commented 8 years ago

Yesterday kotnet/campusnet was down When attempting to log in kotnetcli crashed with the following output:

jo@Giedion[1]::~$ kotnetcli --debug
/usr/lib/python2.7/site-packages/keyring/backend.py:16: UserWarning: Module argparse was already imported from /usr/lib/python2.7/argparse.pyc, but /usr/lib/python2.7/site-packages is being added to sys.path
  import pkg_resources
DEBUG::kotnetcli: parse_args() is: Namespace(color=['green', 'cyan', 'yellow', 'normal'], debug='debug', forget=False, guest_mode=False, keyring=False, license=None, login=False, logout=False, plaintext=False)
INFO::kotnetcli: ik haal de credentials uit de keyring
INFO::kotnetcli: ik wil inloggen
INFO::kotnetcli: ik wil vrolijke custom kleuren: ['green', 'cyan', 'yellow', 'normal']
DEBUG::coloramac: Probeert Colorama te importeren...
DEBUG::coloramac: OK
DEBUG::coloramac: the given colornamelist is ['GREEN', 'CYAN', 'YELLOW', 'NORMAL']
DEBUG::worker: enter LoginWorker.go()
Kotnet verbinding testen... [ OK ]
Netlogin openen............ [ OK ]
Gegevens invoeren.......... [ OK ]
Gegevens opsturen.......... [ OK ]
Traceback (most recent call last):
  File "/media/DATA/Documenten/Programming/python/kotnetcli_fresh/kotnetcli/kotnetcli.py", line 343, in <module>
    main()
  File "/media/DATA/Documenten/Programming/python/kotnetcli_fresh/kotnetcli/kotnetcli.py", line 338, in main
    k.parseArgumenten()
  File "/media/DATA/Documenten/Programming/python/kotnetcli_fresh/kotnetcli/kotnetcli.py", line 199, in parseArgumenten
    worker.go(co, creds)
  File "/media/DATA/Documenten/Programming/python/kotnetcli_fresh/kotnetcli/worker.py", line 62, in go
    self.login_resultaten(co)
  File "/media/DATA/Documenten/Programming/python/kotnetcli_fresh/kotnetcli/worker.py", line 110, in login_resultaten
    tup = self.browser.login_parse_results()
  File "/media/DATA/Documenten/Programming/python/kotnetcli_fresh/kotnetcli/browser.py", line 130, in login_parse_results
    logger.debug("rccode is %s", rccode)
UnboundLocalError: local variable 'rccode' referenced before assignment

Seems like the parser (browser class) couldn't find and thus did not fill in the rccode variable, since the html page did not look as expected? No real problem maybe, but it would be nice if the browser could throw an exception or so when detecting the html response is not as expected. The worker could then catch this exception and inform the communicator of a fatal error... Could something like this be possible?

I am not sure whether the 301 code is an RC code?? As with issue #85 there seem to be two codes involved (exctract from html dump below):

<h2>KotNet/CampusNet</h2>
<!-- <rc=100 password verification successful (user=<kuleuven-campusnet/ANONYMOUS>)>
 -->
301 could not call backend 

I retrieved the full html page with a web browser:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl"> 
<head> 
<title>Netwerk Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="Description" content="KU Leuven, " /> 
<meta name="Keywords" content="KU Leuven, Katholieke Universiteit Leuven, " /> 
<style type="text/css" media="screen, projection"> 
@import url(https://stijl.kuleuven.be/_c/subnav.css);
@import url(https://stijl.kuleuven.be/_c/nieuws.css);
/* embedded styles hier */
</style> 
<link rel="stylesheet" type="text/css" href="https://stijl.kuleuven.be/_c/main.css" title="default" media="screen, projection" /> 
<!--[if lt IE 8]><link rel="stylesheet" type="text/css" href="https://stijl.kuleuven.be/_c/IE.css" media="screen, projection" /><![endif]--> 
<link rel="stylesheet" type="text/css" href="https://stijl.kuleuven.be/_c/handheld.css" media="handheld" /> 
<link rel="stylesheet" type="text/css" href="https://stijl.kuleuven.be/_c/print.css" media="print" />
<link rel="stylesheet" type="text/css" href="/css/style.css" title="default" /> 
</head> 
<body> 
<div id="wrapper"> 
  <div id="header"> 
<h2 class="access">Taakbalk</h2> 
<ul id="access">        
        <li><a href="#mainnav" tabindex="1" accesskey="N">navigatie</a></li> 
        <li><a href="#subnav" tabindex="2" accesskey="S">subnavigatie</a></li> 
        <li><a href="#content" tabindex="3" accesskey="C">inhoud</a></li> 
</ul> 
<ul id="taskbar"> 
        <li class="home"><a href="http://www.kuleuven.be/kuleuven/" tabindex="4" id="top" name="top">home</a></li> 
        <li class="whoiswho"><a href="http://cwisdb.kuleuven.be/persdb-bin/persdb?lang=N&amp;oproep=vraag">wie is wie</a></li> 
        <li class="organigram"><a href="http://organigram.kuleuven.be/">organigram</a></li> 
        <li class="contact"><a href="http://www.kuleuven.be/kuleuven/contact.html">contact</a></li> 
        <li class="intranet"><a href="http://www.kuleuven.be/intranet/">intranet</a></li> 
        <li class="langselect"><a href="http://www.kuleuven.be/english/" title="Choose English">english</a></li> 
</ul> 
<a href="http://www.kuleuven.be/kuleuven/"><img id="logo" src="https://stijl.kuleuven.be/logo_kuleuven.png" width="160" height="53" alt="logo" title="KU Leuven - Home" /></a>
<form action="http://robot.kuleuven.be/index.cgi" method="post" id="searchform" title="zoekformulier" name="searchform"><label for="words">zoekterm: </label> 
<input tabindex="5" type="text" name="words" id="words" title="geef een zoekterm"/><input tabindex="6" type="image" class="magnifier" src="https://stijl.kuleuven.be/_i/icons/icon_magnifier.gif" alt="verstuur" title="zoek nu"/><input type="hidden" name="oproep" value="zoek" /> 
</form> 
</div><!-- end header --> 
<div id="subnav"> 
    <h2><a href="http://admin.kuleuven.be/icts">ICTS</a></h2>    
    <ul id="subnavlist"> 
    <li><a href="http://admin.kuleuven.be/icts/services">Dienstverlening voor de universiteit</a></li><li class="separator"> <br /> </li><li><a href="http://admin.kuleuven.be/icts/helpdesk">Helpdesk</a></li>    </ul> 
  </div> 

<div id="nieuws"> 
<div class="indekijker"> 
            <h3>Meer informatie</h3> 
        <ul>
          <li><a href="https://admin.kuleuven.be/icts/services/kotnet" target="_blank">KotNet algemeen</a></li>
          <li><a href="https://admin.kuleuven.be/icts/services/kotnet/gebruiksvoorwaarden" target="_blank">Gedragscode voor KotNet</a></li>
          <li><a href="http://status.kuleuven.be/kuleuvennet" target="_blank">Netwerk status</a></li>
          <li><a href="http://icts.kuleuven.be/help/" target="_blank">Helpdesk</a></li>
        </ul>
</div> 
<div class="thema"> 
            <h3>More information</h3> 
        <ul>
          <li><a href="http://ludit.kuleuven.be/internet/index_en.html" target="_blank">KotNet in general</a></li>
          <li><a href="http://ludit.kuleuven.be/internet/kotnet/voorwaarden_en.html" target="_blank">KotNet Use Policy</a></li>
          <li><a href="http://status.kuleuven.be/kuleuvennet" target="_blank">Network status</a></li>
          <li><a href="http://icts.kuleuven.be/help/index_en.html" target="_blank">Helpdesk</a></li>
        </ul>
</div> 
</div>    

  <div id="contentwrapper"> 
    <div id="content"> 
      <!-- content starts here --> 
                  <!--<div id="navbar"><span style="display: none">Navigatiebalk: </span><a href="/">Home</a> &gt; <a href="/leeg/">Leeg</a></div> -->

<h1>KotNet/CampusNet</h1>
<h2>Netwerk Login</h2>
        <div class="associatie_logo">
                  <img src="/images/associatie_logo.gif" width="44" height="62" border="0"/>
        </div>

<h2>KotNet/CampusNet</h2>
<!-- <rc=100 password verification successful (user=<kuleuven-campusnet/ANONYMOUS>)>
 -->
301 could not call backend 

      <!-- content ends here --> 
    </div> 
  </div> 
  <!--end contentwrapper--> 
  <div id="footer"> 
     <p>Copyright &copy; KU Leuven | reacties op de inhoud: <a href="mailto:ICTS@kuleuven.be">ICTS</a><br /> 
      Realisatie: <a href="mailto:icts@kuleuven.be">ICTS</a>| <a href="http://www.kuleuven.be/kuleuven/disclaimer.html">Disclaimer</a> 
                  </p> 
  </div> 
</div> 

</body> 
</html> 
GijsTimmers commented 8 years ago

No real problem maybe, but it would be nice if the browser could throw an exception or so when detecting the html response is not as expected.

Definitely.

Seems like the parser (browser class) couldn't find and thus did not fill in the rccode variable, since the html page did not look as expected?

That's true. The parser finds the RC code using a regular expression match. The rc code is usually lead by a small string: weblogin: rc=. For some reason, with this specific error, it's just rc=. Very strange.

I am not sure whether the 301 code is an RC code??

I am not sure either. To me, it looks like the Kotnet programmers did not expect error 301 to happen, and therefore, haven't declared a specific RC code for this purpose yet.

To round off, yes, we do need an exception when the RC code is different than expected.

GijsTimmers commented 8 years ago

And, of course: thank you for reporting this issue.

jovanbulck commented 8 years ago

301 is the rccode for internal script error (see issue #80 ), so I guess what happened here is not anticipated in an rccode (?)

To round off, yes, we do need an exception when the RC code is different than expected.

Not really, we already have an UnknownRCException. What happened here is that the rccode variable was empty, since no rccode has been found in the html page. The python code however tries to print out the empty variable, which raises an exception... We thus need to handle the case were no rccode can be found in the html page...