# Python AUto LOGIn for broadband tikona ---invalid syntax



## Rajesh345 (Oct 16, 2015)

I got this syntax for Tikona broadband autologin , i am using airwire so i changed the URL and i am trying to run in Raspberry Pi with python installed but i am getting error 



```
Orginal thread  where source code posted, but owner  has not posted in thread for long time
```


```
#!/usr/bin/env python 

import sys
import mechanize
import time
from optparse import OptionParser
import getpass

def Login(username,password):
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('*202.38.180.2/userportal/login.do')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    br.form.action = '*202.38.180.2/userportal/login.do'
    br.form.method = 'POST'
    print ">>> submitting.."
    response = br.submit()
    print ">>> got response"
    br.select_form(name="form1")
    br["username"] = XXXXXXX
    br["password"] = 12345
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="*202.38.180.2/userportal/login.do"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def Logout():
    print "Logging out.."
    br = mechanize.Browser()
    response = br.open('*login.tikona.in/userportal/logout.do?svccat=1')
    print response.geturl()
    print response.info()
    print response.read()
def main():
    parser = OptionParser()
    usage = "Usage: %prog -u <username>"
    parser = OptionParser(usage=usage, version="%prog 1.0")
    parser.add_option("-u", "--username",  action="store", type="string",dest="user",  help="Username to login")
    (options, args) = parser.parse_args()
    if options.user:
	password = getpass.getpass()
    	Login(options.user,password)
    else:
       print "Fatal: Required arguments are missing!" 
       print "Use: -h / --help to get help."

if __name__ == "__main__":
   main()
```


ERRORs


```
root@raspberrypi:/home/pi# python autologin.py
  File "autologin.py", line 1
    mport sys
            ^
```


```
root@raspberrypi:/home/pi# ./autologin.py
./autologin.py: line 1: mport: command not found
./autologin.py: line 2: import: command not found
./autologin.py: line 3: import: command not found
from: can't read /var/mail/optparse
./autologin.py: line 5: import: command not found
./autologin.py: line 7: syntax error near unexpected token `('
./autologin.py: line 7: `def Login(username,password):'
root@raspberrypi:/home/pi#
```



can anyone fix the python code error 

AirwireLogin Page source


```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

	<html>
	<head>
	  <title>New Customer Login Page</title>
	  <meta content="Evrsoft First Page" name="GENERATOR">
	  <meta http-equiv="content-type" content="text/html; charset=us-ascii">
	  
	  <script type="text/javascript" src="*ff.kis.scr.kaspersky-labs.com/1B74BD89-2A22-4B93-B451-1C9E1052A0EC/main.js" charset="UTF-8"></script><script language="JavaScript" src="pages/js/common.js"></script>
	  <script type="text/javascript">
	  function onSubmit(){
		  
		  if(document.forms[0].username.value==""){
				alert("Please enter Username");
				document.forms[0].username.focus();
				return false;
				
			}else if(document.forms[0].password.value==""){
					alert("Please enter Password");
					document.forms[0].password.focus();
					return false;
			}
		if (document.forms[0].rememberme.checked)
				{	
					createCookie('nasusername',document.forms[0].username.value,2);
					createCookie('type',document.forms[0].type.value,2);
					createCookie('nasrememberme',1,2);
							
				}
				else
				{
					eraseCookie('nasusername');
					eraseCookie('type');
					eraseCookie('nasrememberme');
				}
				
				//	document.forms[0].action = "newlogin.do?phone=0";
				//	document.forms[0].method = "post";
				//	document.forms[0].submit();
				//	return true;
				
	  }
	   function go_now()
	   {
	   	window.open("*1.254.254.254/","RequestIP");
		   }

	function bodyOnload()
	{
	setTimeout("go_now()",2000); 
                        document.forms[0].type.selectedIndex = "0";
			if (document.forms[0].username.value.length ==0)
				document.forms[0].username.focus();
			else
				document.forms[0].password.focus();
			
			
	}
	function getSettings()
	{
		
	   var usrname=readCookie('nasusername');
	   var dom=readCookie('type');
	   document.forms[0].username.value = usrname;
	   document.forms[0].type.value = dom;
	   document.forms[0].password.value="";
	   if(usrname==null){
			document.forms[0].username.value = "";
			document.forms[0].type.value = "";
			document.forms[0].rememberme.checked=false;
			document.forms[0].username.focus();
		}
		else{
			if(usrname.length<=0)
				document.forms[0].rememberme.checked=false;
			else
				document.forms[0].rememberme.checked=true;
			document.forms[0].password.focus();
		}
		
	
			
					
						
			var dt = '10/26/2015 16:03:00';
			var currentdate = new Date();
			var expirydate = new Date(dt);
			var month = expirydate.getMonth();
			var date = expirydate.getDate();


			
			var ex_second =( expirydate.getTime() - currentdate.getTime())/1000;
		
			if(ex_second<=86400*7)
			{
				var k;
				for(k=7;k>=1;k--) 
				{
					if(ex_second<=86400*k && ex_second>86400*(k-1))
					{                                       
									  
					alert("Dear Customer, your broadband subscription is going to expire within  "+k+"day(s), pls recharge your  internet ID to enjoy uninterrupted services.");
										
					}
				}
			}
				}
				

	function createCookie(name,value,days)
	{
	   if (days) 
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
	  else
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
		
	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) 
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}


	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
	
	  </script>
		
	  <style>
	  body{font-family:Arial, Helvetica, sans-serif;}
	  .smalltext {
	color:#333333;
	font-family:Verdana,Arial,Helvetica;
	font-size:11px;
	text-align:left;
	}
	.tborder {
	background-color:#FFFFFF;
	border:1px solid #6393DF;
	color:#000000;
	}</style>

	 
	</head>

	<body   onload="getSettings(); bodyOnload();" >
<!-- *1.254.254.254/ -->

	<form action="newlogin.do" method="post" onsubmit="return onSubmit();">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
                    <td><img src="/userportal/pages/images/airwire.jpg" ></td>
                </tr>
						 <tr>
						<td  align="center" valign="top"> 
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<tr>
									<td bgcolor="#3894e5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#83bff5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#c3e3ff" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
							</table>  
	 

	  <br>
	  
	  <div style="float:left; padding:5px 0px; background-color:#6d9de9; border:1px solid #3e79d7; font-size:16px; font-weight:bold; width:288px; margin-left:3px;">
    <a style="color:#ffffff;" href="/userportal/logout.do?svccat=1">Click here to Logout</a></td>
	  </div>
	  
	  <div align="left">

		<table width="600"><tr><td width="570">
		  <table style="WIDTH: 80%; HEIGHT: 130px; TEXT-ALIGN: center" class="tborder" cellspacing="2" cellpadding="2" border="0">
			<tbody>
			<tr><td colspan="3" style="background-color:#6D9DE9; color:#ffffff; font-size:14px; font-weight:bold;" align="left">Login</td></tr>
			  <tr>
				<td class="smalltext" width="40%" align="left">Username</td>
				<td width="10%"></td>
				<td width="50%" align="left"><input type="text" name="username"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left"> Password</td>
				<td></td>
				<td align="left"><input type="password" name="password"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left">Service Type</td>
				<td></td>
				<td align="left"><select name="type">
				  
							<option value="1" >Account</option>
						</select></td>
			  </tr>          
			  <tr>
				<td class="smalltext" align="left">Remember me</td>
				<td></td>
				<td align="left"><input type="checkbox" name="rememberme" id="rememberme"></td>
			  </tr>

			  <tr> 
				<td></td>
				<td></td>         
				<td align="left"><input type="submit" value="Submit"></td>
			  </tr>

			</tbody>

		 </table><input type="hidden" value="0" name="phone"> <input type="hidden" value="1" name="fromTemplate"></td><td width="606">

			</td></tr></table>

	</div> 

	<tr>
    <td>
			<table width="100%">
            <tr>
	<td width="766" height="103">
				<div style="color: #336699; font-size: 12px; font-weight:bold; text-align:center;"></a>&copy;  

NORTH EAST DATA NETWORK PVT LTD </div>
			</td>
		</tr>
	</table>
</td>
</tr>
</table>
		</form>
	</body>
	</html>
```


----------



## Faun (Oct 16, 2015)

> import sys



missing i ?

and add this as the first line in your python file



> #!/usr/bin/python


----------



## Rajesh345 (Oct 16, 2015)

```
pi@raspberrypi ~ $ python autoLogin03.py
Traceback (most recent call last):
  File "autoLogin03.py", line 4, in <module>
    import mechanize
ImportError: No module named mechanize
pi@raspberrypi ~ $
```



```
#!/usr/bin/python 
#
import sys
import mechanize
import time
from optparse import OptionParser
import getpass

def Login(username,password):
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('*202.38.180.2/userportal/login.do')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    br.form.action = '*202.38.180.2/userportal/login.do'
    br.form.method = 'POST'
    print ">>> submitting.."
    response = br.submit()
    print ">>> got response"
    br.select_form(name="form1")
    br["username"] = Abhishek15
    br["password"] = 12345
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="*202.38.180.2/userportal/login.do"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def Logout():
    print "Logging out.."
    br = mechanize.Browser()
    response = br.open('*login.tikona.in/userportal/logout.do?svccat=1')
    print response.geturl()
    print response.info()
    print response.read()
def main():
    parser = OptionParser()
    usage = "Usage: %prog -u <username>"
    parser = OptionParser(usage=usage, version="%prog 1.0")
    parser.add_option("-u", "--username",  action="store", type="string",dest="user",  help="Username to login")
    (options, args) = parser.parse_args()
    if options.user:
	password = getpass.getpass()
    	Login(options.user,password)
    else:
       print "Fatal: Required arguments are missing!" 
       print "Use: -h / --help to get help."

if __name__ == "__main__":
   main()
```


Sorry Orginal LINK got missed in my first post

```
*www.brijin.net/login-to-tikona/
```



```
how to use this python script in windows for login in tikona and where is help to use?
Reply

    Bris
    February 1st, 2013 at 4:55 PM

    You need to install Python & the mechanize module for python. That’s it. Also you can put the whole script inside a py file and double click on it to connect. :-)

    C:\Users\bris\python>python.exe tikona.py -h
    Usage: tikona.py -u

    Options:
    –version show program’s version number and exit
    -h, –help show this help message and exit
    -u USER, –username=USER
    Username to login

    C:\Users\bris\python>
```

Progress 

I used 

apt-get install python-mechanize 

command in my Raspberry PI 

now when i run the scrip i get

```
pi@raspberrypi ~ $ ./autologin04.py
./autologin04.py: line 3: import: command not found
./autologin04.py: line 4: import: command not found
./autologin04.py: line 5: import: command not found
from: can't read /var/mail/optparse
./autologin04.py: line 7: import: command not found
./autologin04.py: line 9: syntax error near unexpected token `('
./autologin04.py: line 9: `def Login(username,password):'
pi@raspberrypi ~ $
```



FROM his Orginal  thread 


```
Bris
August 16th, 2013 at 9:41 PM

Hi,

You are trying to set it up on a Windows machine? I’ve never tested it on Win platforms. Anyway it should work but it’s written in python 2x version. You will have to download 2.5 or later (must be <3) and install mechanize module in it to make it work.
```


PROGRESS



```
pi@raspberrypi ~ $ python
python            python2.7         python3.2         python-config
python2           python2.7-config  python3.2mu
python2.6         python3           python3mu

pi@raspberrypi ~ $ python3 auto
autoLogin03.py  autologin04.py  autologin2.py   autologin.py
```


```
pi@raspberrypi ~ $ python3 autologin04.py
  File "autologin04.py", line 10
    print ">>> trying to connect.."
                                  ^
SyntaxError: invalid syntax
```


```
pi@raspberrypi ~ $ python2.6 autologin04.py
Fatal: Required arguments are missing!
Use: -h / --help to get help.
```


```
pi@raspberrypi ~ $ python2 autologin04.py
Fatal: Required arguments are missing!
Use: -h / --help to get help.
```
pi@raspberrypi ~ $ python2.7 autologin04.py
Fatal: Required arguments are missing!
Use: -h / --help to get help.

[/code]

```
pi@raspberrypi ~ $ python3.2 autologin04.py
  File "autologin04.py", line 10
    print ">>> trying to connect.."
                                  ^
SyntaxError: invalid syntax
pi@raspberrypi ~ $
```
[/code]


----------



## Faun (Oct 17, 2015)

Run this


> python autologin04.py -u your_username



replace your_username with your actual username

You can avoid entering username password too. Use this code:

```
#!/usr/bin/python 
#
import sys
import mechanize
import time

def Login():
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('*202.38.180.2/userportal/login.do')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    br.form.action = '*202.38.180.2/userportal/login.do'
    br.form.method = 'POST'
    print ">>> submitting.."
    response = br.submit()
    print ">>> got response"
    br.select_form(name="form1")
    br["username"] = Abhishek15
    br["password"] = 12345
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="*202.38.180.2/userportal/login.do"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def main():   
    	Login()

if __name__ == "__main__":
   main()
```

Replace the text on right side with actual username and password in the above code

br["username"] = Abhishek15
br["password"] = 12345


----------



## Rajesh345 (Oct 18, 2015)

Faun said:


> Run this
> 
> 
> replace your_username with your actual username
> ...



thank you for trying to help 
its updated


```
pi@raspberrypi ~ $ python3 autologin04.py
  File "autologin04.py", line 10
    print ">>> trying to connect.."
                                  ^
SyntaxError: invalid syntax
pi@raspberrypi ~ $ python2. autologin04.py
python2.6         python2.7         python2.7-config
pi@raspberrypi ~ $ python2.7 autologin04.py
Fatal: Required arguments are missing!
Use: -h / --help to get help.
pi@raspberrypi ~ $ python2.7 autologin04.py -h
Usage: autologin04.py -u <username>

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -u USER, --username=USER
                        Username to login
pi@raspberrypi ~ $ python2.7 autologin04.py -u Abhishek15
Password:
>>> trying to connect..
>>> ok
>>> Powered by Inventum
>>> redirecting to login.do
>>> submitting..
>>> got response
Traceback (most recent call last):
  File "autologin04.py", line 65, in <module>
    main()
  File "autologin04.py", line 59, in main
    Login(options.user,password)
  File "autologin04.py", line 24, in Login
    br.select_form(name="form1")
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 524, in         select_form
    raise FormNotFoundError("no form matching "+description)
mechanize._mechanize.FormNotFoundError: no form matching name 'form1'
pi@raspberrypi ~ $
```


----------



## Faun (Oct 18, 2015)

*202.38.180.2/userportal/login.do is not live. Can you see the URL working in your web browser ?

Do you know the new URL ?


----------



## Rajesh345 (Oct 18, 2015)

Faun said:


> *202.38.180.2/userportal/login.do is not live. Can you see the URL working in your web browser ?
> 
> Do you know the new URL ?





*s1.postimg.org/xgx4urtnz/image.png
*s1.postimg.org/ed3tefgtr/image.png


i think link is accessible only from their ISP network


----------



## Faun (Oct 18, 2015)

Replace this 
br.select_form(name="form1")

with
br.select_form(nr=0)


If that doesn't work then post the html source of the login page. I will need to confirm form name.


----------



## Rajesh345 (Oct 18, 2015)

i found two line commented out in source code , so i enabled it 

```
#print response.geturl()
    #print ">>>"
```


```
#response.get_data()
```


```
pi@raspberrypi ~ $ python2.7 autologin01.py -u Abhishek15
Password:
>>> trying to connect..
>>> ok
>>> Powered by Inventum
*202.38.180.2/userportal/?requesturi=http%3a%2f%2f1%2e254%2e254%2e254%2fuserportal%2flogin%2edo&ip=172%2e17%2e60%2e114&mac=e8%3ade%3a27%3a47%3a52%3ad6&nas=starlink&requestip=1%2e254%2e254%2e254&sc=fad8137fd7006f7f388ede89bbc0a63b
>>>
>>> redirecting to login.do
>>> submitting..
>>> got response
Traceback (most recent call last):
  File "autologin01.py", line 66, in <module>
    main()
  File "autologin01.py", line 60, in main
    Login(options.user,password)
  File "autologin01.py", line 24, in Login
    br.select_form(name="form1")
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 524, in select_form
    raise FormNotFoundError("no form matching "+description)
mechanize._mechanize.FormNotFoundError: no form matching name 'form1'
pi@raspberrypi ~ $
```

- - - Updated - - -



Faun said:


> Replace this
> br.select_form(name="form1")
> 
> with
> ...



Sir, replaced


```
pi@raspberrypi ~ $ python2.7 autologin01.py -u Abhishek15
Password:
>>> trying to connect..
>>> ok
>>> Powered by Inventum
*202.38.180.2/userportal/?requesturi=http%3a%2f%2f1%2e254%2e254%2e254%2fuserportal%2flogin%2edo&ip=172%2e17%2e60%2e114&mac=e8%3ade%3a27%3a47%3a52%3ad6&nas=starlink&requestip=1%2e254%2e254%2e254&sc=fad8137fd7006f7f388ede89bbc0a63b
>>>
>>> redirecting to login.do
>>> submitting..
>>> got response
Traceback (most recent call last):
  File "autologin01.py", line 66, in <module>
    main()
  File "autologin01.py", line 60, in main
    Login(options.user,password)
  File "autologin01.py", line 24, in Login
    br.select_form(name="nr=0")
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 524, in select_form
    raise FormNotFoundError("no form matching "+description)
mechanize._mechanize.FormNotFoundError: no form matching name 'nr=0'
pi@raspberrypi ~ $
```



Sir Using view page source i posting their login page source


```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

	<html>
	<head>
	  <title>New Customer Login Page</title>
	  <meta content="Evrsoft First Page" name="GENERATOR">
	  <meta http-equiv="content-type" content="text/html; charset=us-ascii">
	  
	  <script type="text/javascript" src="*ff.kis.scr.kaspersky-labs.com/1B74BD89-2A22-4B93-B451-1C9E1052A0EC/main.js" charset="UTF-8"></script><script language="JavaScript" src="pages/js/common.js"></script>
	  <script type="text/javascript">
	  function onSubmit(){
		  
		  if(document.forms[0].username.value==""){
				alert("Please enter Username");
				document.forms[0].username.focus();
				return false;
				
			}else if(document.forms[0].password.value==""){
					alert("Please enter Password");
					document.forms[0].password.focus();
					return false;
			}
		if (document.forms[0].rememberme.checked)
				{	
					createCookie('nasusername',document.forms[0].username.value,2);
					createCookie('type',document.forms[0].type.value,2);
					createCookie('nasrememberme',1,2);
							
				}
				else
				{
					eraseCookie('nasusername');
					eraseCookie('type');
					eraseCookie('nasrememberme');
				}
				
				//	document.forms[0].action = "newlogin.do?phone=0";
				//	document.forms[0].method = "post";
				//	document.forms[0].submit();
				//	return true;
				
	  }
	   function go_now()
	   {
	   	window.open("*1.254.254.254/","RequestIP");
		   }

	function bodyOnload()
	{
	setTimeout("go_now()",2000); 
                        document.forms[0].type.selectedIndex = "0";
			if (document.forms[0].username.value.length ==0)
				document.forms[0].username.focus();
			else
				document.forms[0].password.focus();
			
			
	}
	function getSettings()
	{
		
	   var usrname=readCookie('nasusername');
	   var dom=readCookie('type');
	   document.forms[0].username.value = usrname;
	   document.forms[0].type.value = dom;
	   document.forms[0].password.value="";
	   if(usrname==null){
			document.forms[0].username.value = "";
			document.forms[0].type.value = "";
			document.forms[0].rememberme.checked=false;
			document.forms[0].username.focus();
		}
		else{
			if(usrname.length<=0)
				document.forms[0].rememberme.checked=false;
			else
				document.forms[0].rememberme.checked=true;
			document.forms[0].password.focus();
		}
		
	
			
					
						
			var dt = '10/26/2015 16:03:00';
			var currentdate = new Date();
			var expirydate = new Date(dt);
			var month = expirydate.getMonth();
			var date = expirydate.getDate();


			
			var ex_second =( expirydate.getTime() - currentdate.getTime())/1000;
		
			if(ex_second<=86400*7)
			{
				var k;
				for(k=7;k>=1;k--) 
				{
					if(ex_second<=86400*k && ex_second>86400*(k-1))
					{                                       
									  
					alert("Dear Customer, your broadband subscription is going to expire within  "+k+"day(s), pls recharge your  internet ID to enjoy uninterrupted services.");
										
					}
				}
			}
				}
				

	function createCookie(name,value,days)
	{
	   if (days) 
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
	  else
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
		
	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) 
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}


	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
	
	  </script>
		
	  <style>
	  body{font-family:Arial, Helvetica, sans-serif;}
	  .smalltext {
	color:#333333;
	font-family:Verdana,Arial,Helvetica;
	font-size:11px;
	text-align:left;
	}
	.tborder {
	background-color:#FFFFFF;
	border:1px solid #6393DF;
	color:#000000;
	}</style>

	 
	</head>

	<body   onload="getSettings(); bodyOnload();" >
<!-- *1.254.254.254/ -->

	<form action="newlogin.do" method="post" onsubmit="return onSubmit();">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
                    <td><img src="/userportal/pages/images/airwire.jpg" ></td>
                </tr>
						 <tr>
						<td  align="center" valign="top"> 
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<tr>
									<td bgcolor="#3894e5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#83bff5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#c3e3ff" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
							</table>  
	 

	  <br>
	  
	  <div style="float:left; padding:5px 0px; background-color:#6d9de9; border:1px solid #3e79d7; font-size:16px; font-weight:bold; width:288px; margin-left:3px;">
    <a style="color:#ffffff;" href="/userportal/logout.do?svccat=1">Click here to Logout</a></td>
	  </div>
	  
	  <div align="left">

		<table width="600"><tr><td width="570">
		  <table style="WIDTH: 80%; HEIGHT: 130px; TEXT-ALIGN: center" class="tborder" cellspacing="2" cellpadding="2" border="0">
			<tbody>
			<tr><td colspan="3" style="background-color:#6D9DE9; color:#ffffff; font-size:14px; font-weight:bold;" align="left">Login</td></tr>
			  <tr>
				<td class="smalltext" width="40%" align="left">Username</td>
				<td width="10%"></td>
				<td width="50%" align="left"><input type="text" name="username"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left"> Password</td>
				<td></td>
				<td align="left"><input type="password" name="password"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left">Service Type</td>
				<td></td>
				<td align="left"><select name="type">
				  
							<option value="1" >Account</option>
						</select></td>
			  </tr>          
			  <tr>
				<td class="smalltext" align="left">Remember me</td>
				<td></td>
				<td align="left"><input type="checkbox" name="rememberme" id="rememberme"></td>
			  </tr>

			  <tr> 
				<td></td>
				<td></td>         
				<td align="left"><input type="submit" value="Submit"></td>
			  </tr>

			</tbody>

		 </table><input type="hidden" value="0" name="phone"> <input type="hidden" value="1" name="fromTemplate"></td><td width="606">

			</td></tr></table>

	</div> 

	<tr>
    <td>
			<table width="100%">
            <tr>
	<td width="766" height="103">
				<div style="color: #336699; font-size: 12px; font-weight:bold; text-align:center;"></a>&copy;  

NORTH EAST DATA NETWORK PVT LTD </div>
			</td>
		</tr>
	</table>
</td>
</tr>
</table>
		</form>
	</body>
	</html>
```



*s27.postimg.org/g9xvfbter/image.png


----------



## Faun (Oct 18, 2015)

Post the login page source. No other way to find out form selector. I will be able to help then.

Also post your updated program too.


----------



## Rajesh345 (Oct 18, 2015)

Faun said:


> Post the login page source. No other way to find out form selector. I will be able to help then.
> 
> Also post your updated program too.




```
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

	<html>
	<head>
	  <title>New Customer Login Page</title>
	  <meta content="Evrsoft First Page" name="GENERATOR">
	  <meta http-equiv="content-type" content="text/html; charset=us-ascii">
	  
	  <script type="text/javascript" src="*ff.kis.scr.kaspersky-labs.com/1B74BD89-2A22-4B93-B451-1C9E1052A0EC/main.js" charset="UTF-8"></script><script language="JavaScript" src="pages/js/common.js"></script>
	  <script type="text/javascript">
	  function onSubmit(){
		  
		  if(document.forms[0].username.value==""){
				alert("Please enter Username");
				document.forms[0].username.focus();
				return false;
				
			}else if(document.forms[0].password.value==""){
					alert("Please enter Password");
					document.forms[0].password.focus();
					return false;
			}
		if (document.forms[0].rememberme.checked)
				{	
					createCookie('nasusername',document.forms[0].username.value,2);
					createCookie('type',document.forms[0].type.value,2);
					createCookie('nasrememberme',1,2);
							
				}
				else
				{
					eraseCookie('nasusername');
					eraseCookie('type');
					eraseCookie('nasrememberme');
				}
				
				//	document.forms[0].action = "newlogin.do?phone=0";
				//	document.forms[0].method = "post";
				//	document.forms[0].submit();
				//	return true;
				
	  }
	   function go_now()
	   {
	   	window.open("*1.254.254.254/","RequestIP");
		   }

	function bodyOnload()
	{
	setTimeout("go_now()",2000); 
                        document.forms[0].type.selectedIndex = "0";
			if (document.forms[0].username.value.length ==0)
				document.forms[0].username.focus();
			else
				document.forms[0].password.focus();
			
			
	}
	function getSettings()
	{
		
	   var usrname=readCookie('nasusername');
	   var dom=readCookie('type');
	   document.forms[0].username.value = usrname;
	   document.forms[0].type.value = dom;
	   document.forms[0].password.value="";
	   if(usrname==null){
			document.forms[0].username.value = "";
			document.forms[0].type.value = "";
			document.forms[0].rememberme.checked=false;
			document.forms[0].username.focus();
		}
		else{
			if(usrname.length<=0)
				document.forms[0].rememberme.checked=false;
			else
				document.forms[0].rememberme.checked=true;
			document.forms[0].password.focus();
		}
		
	
			
					
						
			var dt = '10/26/2015 16:03:00';
			var currentdate = new Date();
			var expirydate = new Date(dt);
			var month = expirydate.getMonth();
			var date = expirydate.getDate();


			
			var ex_second =( expirydate.getTime() - currentdate.getTime())/1000;
		
			if(ex_second<=86400*7)
			{
				var k;
				for(k=7;k>=1;k--) 
				{
					if(ex_second<=86400*k && ex_second>86400*(k-1))
					{                                       
									  
					alert("Dear Customer, your broadband subscription is going to expire within  "+k+"day(s), pls recharge your  internet ID to enjoy uninterrupted services.");
										
					}
				}
			}
				}
				

	function createCookie(name,value,days)
	{
	   if (days) 
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
	  else
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
		
	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) 
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}


	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
	
	  </script>
		
	  <style>
	  body{font-family:Arial, Helvetica, sans-serif;}
	  .smalltext {
	color:#333333;
	font-family:Verdana,Arial,Helvetica;
	font-size:11px;
	text-align:left;
	}
	.tborder {
	background-color:#FFFFFF;
	border:1px solid #6393DF;
	color:#000000;
	}</style>

	 
	</head>

	<body   onload="getSettings(); bodyOnload();" >
<!-- *1.254.254.254/ -->

	<form action="newlogin.do" method="post" onsubmit="return onSubmit();">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
                    <td><img src="/userportal/pages/images/airwire.jpg" ></td>
                </tr>
						 <tr>
						<td  align="center" valign="top"> 
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<tr>
									<td bgcolor="#3894e5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#83bff5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#c3e3ff" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
							</table>  
	 

	  <br>
	  
	  <div style="float:left; padding:5px 0px; background-color:#6d9de9; border:1px solid #3e79d7; font-size:16px; font-weight:bold; width:288px; margin-left:3px;">
    <a style="color:#ffffff;" href="/userportal/logout.do?svccat=1">Click here to Logout</a></td>
	  </div>
	  
	  <div align="left">

		<table width="600"><tr><td width="570">
		  <table style="WIDTH: 80%; HEIGHT: 130px; TEXT-ALIGN: center" class="tborder" cellspacing="2" cellpadding="2" border="0">
			<tbody>
			<tr><td colspan="3" style="background-color:#6D9DE9; color:#ffffff; font-size:14px; font-weight:bold;" align="left">Login</td></tr>
			  <tr>
				<td class="smalltext" width="40%" align="left">Username</td>
				<td width="10%"></td>
				<td width="50%" align="left"><input type="text" name="username"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left"> Password</td>
				<td></td>
				<td align="left"><input type="password" name="password"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left">Service Type</td>
				<td></td>
				<td align="left"><select name="type">
				  
							<option value="1" >Account</option>
						</select></td>
			  </tr>          
			  <tr>
				<td class="smalltext" align="left">Remember me</td>
				<td></td>
				<td align="left"><input type="checkbox" name="rememberme" id="rememberme"></td>
			  </tr>

			  <tr> 
				<td></td>
				<td></td>         
				<td align="left"><input type="submit" value="Submit"></td>
			  </tr>

			</tbody>

		 </table><input type="hidden" value="0" name="phone"> <input type="hidden" value="1" name="fromTemplate"></td><td width="606">

			</td></tr></table>

	</div> 

	<tr>
    <td>
			<table width="100%">
            <tr>
	<td width="766" height="103">
				<div style="color: #336699; font-size: 12px; font-weight:bold; text-align:center;"></a>&copy;  

NORTH EAST DATA NETWORK PVT LTD </div>
			</td>
		</tr>
	</table>
</td>
</tr>
</table>
		</form>
	</body>
	</html>
```

*s27.postimg.org/g9xvfbter/image.png


i reverted the change to old

Updated source code


```
#!/usr/bin/env python 

import sys
import mechanize
import time
from optparse import OptionParser
import getpass

def Login(username,password):
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('*1.254.254.254/userportal/login.do')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    br.form.action = '*1.254.254.254/userportal/login.do'
    br.form.method = 'POST'
    print ">>> submitting.."
    response = br.submit()
    print ">>> got response"
    br.select_form(name="form1")
    br["username"] = Abhishek15
    br["password"] = 12345
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="*1.254.254.254/userportal/login.do"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def Logout():
    print "Logging out.."
    br = mechanize.Browser()
    response = br.open('*1.254.254.254/userportal/login.do')
    print response.geturl()
    print response.info()
    print response.read()
def main():
    parser = OptionParser()
    usage = "Usage: %prog -u <username>"
    parser = OptionParser(usage=usage, version="%prog 1.0")
    parser.add_option("-u", "--username",  action="store", type="string",dest="user",  help="Username to login")
    (options, args) = parser.parse_args()
    if options.user:
	password = getpass.getpass()
    	Login(options.user,password)
    else:
       print "Fatal: Required arguments are missing!" 
       print "Use: -h / --help to get help."

if __name__ == "__main__":
   main()
```

Updated responce 



```
pi@raspberrypi ~ $ python autologin3.py -u Abhishek15
Password:
>>> trying to connect..
>>> ok
>>> Powered by Inventum
>>> redirecting to login.do
>>> submitting..
>>> got response
Traceback (most recent call last):
  File "autologin3.py", line 65, in <module>
    main()
  File "autologin3.py", line 59, in main
    Login(options.user,password)
  File "autologin3.py", line 24, in Login
    br.select_form(name="form1")
  File "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 524, in select_form
    raise FormNotFoundError("no form matching "+description)
mechanize._mechanize.FormNotFoundError: no form matching name 'form1'
pi@raspberrypi ~ $
```


----------



## Faun (Oct 18, 2015)

Try this


```
#!/usr/bin/env python 

import sys
import mechanize
import time
from optparse import OptionParser
import getpass

def Login(username,password):
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('*1.254.254.254/userportal/login.do')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    #br.form.action = '*1.254.254.254/userportal/login.do'
    #br.form.method = 'POST'
    print ">>> filling form.."
    #response = br.submit()
    #print ">>> got response"
    #br.select_form(name="form1")
    br["username"] = Abhishek15
    br["password"] = 12345
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="*1.254.254.254/userportal/login.do"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def Logout():
    print "Logging out.."
    br = mechanize.Browser()
    response = br.open('*1.254.254.254/userportal/login.do')
    print response.geturl()
    print response.info()
    print response.read()
def main():
    parser = OptionParser()
    usage = "Usage: %prog -u <username>"
    parser = OptionParser(usage=usage, version="%prog 1.0")
    parser.add_option("-u", "--username",  action="store", type="string",dest="user",  help="Username to login")
    (options, args) = parser.parse_args()
    if options.user:
	password = getpass.getpass()
    	Login(options.user,password)
    else:
       print "Fatal: Required arguments are missing!" 
       print "Use: -h / --help to get help."

if __name__ == "__main__":
   main()
```


----------



## Rajesh345 (Oct 18, 2015)

Faun said:


> Try this
> 
> 
> ```
> ...




pi@raspberrypi ~ $ python2.7 autologin05.py -u Abhishek15
Password:
>>> trying to connect..
>>> ok
>>> Powered by Inventum
>>> redirecting to login.do
>>> filling form..
Traceback (most recent call last):
  File "autologin05.py", line 65, in <module>
    main()
  File "autologin05.py", line 59, in main
    Login(options.user,password)
  File "autologin05.py", line 25, in Login
    br["username"] = Abhishek15
NameError: global name 'Abhishek15' is not defined


----------



## Faun (Oct 18, 2015)

Rajesh345 said:


> pi@raspberrypi ~ $ python2.7 autologin05.py -u Abhishek15
> Password:
> >>> trying to connect..
> >>> ok
> ...



Haha...it should be string, try this:


```
#!/usr/bin/env python 

import sys
import mechanize
import time
from optparse import OptionParser
import getpass

def Login(username,password):
    print ">>> trying to connect.."
    br = mechanize.Browser()
    response  = br.open('*1.254.254.254/userportal/login.do')
    print ">>> ok"
    print ">>> " + br.title()
    #print response.geturl()
    #print ">>>"
    print ">>> redirecting to login.do"
    br.select_form(nr=0)
    #br.form.action = '*1.254.254.254/userportal/login.do'
    #br.form.method = 'POST'
    print ">>> filling form.."
    #response = br.submit()
    #print ">>> got response"
    #br.select_form(name="form1")
    br["username"] = "Abhishek15"
    br["password"] = "12345"
    br.find_control(name="type").value = ["2"]
    br.form.method="POST"
    print ">>> proceeding to login.."
    br.form.action="*1.254.254.254/userportal/login.do"
    print ">>> loggin in..."
    print ">>> ok " 
    print ">>> " + br.title()
    response = br.submit()
    #response.get_data()
    print ""
    print 50 * "*"
    print ""
    print response.info()
    print 50 * "*"
    print ""
    #print response.read()

def Logout():
    print "Logging out.."
    br = mechanize.Browser()
    response = br.open('*1.254.254.254/userportal/login.do')
    print response.geturl()
    print response.info()
    print response.read()
def main():
    parser = OptionParser()
    usage = "Usage: %prog -u <username>"
    parser = OptionParser(usage=usage, version="%prog 1.0")
    parser.add_option("-u", "--username",  action="store", type="string",dest="user",  help="Username to login")
    (options, args) = parser.parse_args()
    if options.user:
	password = getpass.getpass()
    	Login(options.user,password)
    else:
       print "Fatal: Required arguments are missing!" 
       print "Use: -h / --help to get help."

if __name__ == "__main__":
   main()
```


----------



## Rajesh345 (Oct 18, 2015)

Faun said:


> Haha...it should be string, try this:
> 
> 
> ```
> ...




```
pi@raspberrypi ~ $ python2.7 autologin07.py -u Abhishek15
Password:
>>> trying to connect..
>>> ok
>>> Powered by Inventum
>>> redirecting to login.do
>>> filling form..
Traceback (most recent call last):
  File "autologin07.py", line 65, in <module>
    main()
  File "autologin07.py", line 59, in main
    Login(options.user,password)
  File "autologin07.py", line 25, in Login
    br["username"] = "Abhishek15"
  File "/usr/lib/python2.7/dist-packages/mechanize/_form.py", line 2780, in __setitem__
    control = self.find_control(name)
  File "/usr/lib/python2.7/dist-packages/mechanize/_form.py", line 3101, in find_control
    return self._find_control(name, type, kind, id, label, predicate, nr)
  File "/usr/lib/python2.7/dist-packages/mechanize/_form.py", line 3185, in _find_control
    raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'username'
```

sir, posted updated error message


----------



## Faun (Oct 18, 2015)

If you don't mind, give me your screen access through teamviewer. Troubleshooting like this is just slow and doesnt make sense.

Message me your pc's teamviewer id.


----------



## Rajesh345 (Oct 20, 2015)

Faun said:


> If you don't mind, give me your screen access through teamviewer. Troubleshooting like this is just slow and doesnt make sense.
> 
> Message me your pc's teamviewer id.



Any update ?   sorry for disturbing again


----------



## Faun (Oct 21, 2015)

Rajesh345 said:


> Any update ?   sorry for disturbing again



Hi dude, remind me today via mail. I will try the POST method.


----------



## Rajesh345 (Oct 22, 2015)

thank u, will send mail

- - - Updated - - -

- - - Updated - - -

i dont know how to thank you , i scheduled the script via crontab job (1minutes)  now i am like 24*7 downloading 

thank you very much 
Currenty Setup

ISP  ---> Router  ---->Raspberry pi2   [Running 2015-05-05-raspbian-wheezy]  

Raspberry pi2 
-  8GB Class 10 SDcard----Installed Raspbian OS on it   
    -Transmission- Torrent client 
    - Pyload - http /fttp downloader 


32 GB USB pen drive   - Download's

Initial guide i used to setup 

How to Turn a Raspberry Pi into a Low-Power Network Storage Device

and i dont remember the orginal thread used to install transmission but its easy 

TechJawab.com: How to install Transmission on Raspberry Pi (with external storage)


then *Custom python script by  Faun* for BBNL broadband to Auto login ISP's capactive login page when net disconnects

- - - Updated - - -

today autologin failed, i guess due to cookie value changed , any possible solution rather than modifing the cookie value like dynamically obtain cookie value ?


EDIT

will this helps ?

How to set and retrieve cookie in http header in python - Stack Overflow 

but not sure how to implement in ur code



edit

sir with the below code i am able to obtain cookie ID

```
from urllib2 import Request, build_opener, HTTPCookieProcessor, HTTPHandler
import cookielib

#Create a CookieJar object to hold the cookies
cj = cookielib.CookieJar()
#Create an opener to open pages using the http protocol and to process cookies.
opener = build_opener(HTTPCookieProcessor(cj), HTTPHandler())

#create a request object to be used to get the page.
#req = Request("*www.google.co.in")

req = Request("*202.38.180.2/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F")
# req = Request("*202.38.180.2/userportal/newlogin.do")
f = opener.open(req)

#see the first few lines of the page
html = f.read()
print html[:50]

#Check out the cookies
print "the cookies are: "
for cookie in cj:
    print cookie
```


output



```
C:\pyth>1.py
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Trans
the cookies are:
<Cookie JSESSIONID=B793EC02BB1337DAE4DA9945515564CB for 202.38.180.2/userportal>
```

but now how to read that value and put in the code u designed ?


----------



## Rajesh345 (Nov 4, 2015)

Everything was working fine , i did reinstall of raspberry PI's OS to arch linux then install python 


but now getting error 


```
[root@alarmpi ~]# python airling.py
  File "airling.py", line 22
    print cookie.value
               ^
SyntaxError: Missing parentheses in call to 'print'
[root@alarmpi ~]#
```

but same code working perfect in desktop PC


```
#!/usr/bin/env pytho
import requests
import urllib2
from urllib2 import Request, build_opener, HTTPCookieProcessor, HTTPHandler
import cookielib
opener = urllib2.build_opener()

#Create a CookieJar object to hold the cookies
cj = cookielib.CookieJar()

#Create an opener to open pages using the http protocol and to process cookies.
opener = build_opener(HTTPCookieProcessor(cj), HTTPHandler())

#create a request object to be used to get the page.

req = Request("*202.38.180.2/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F")

f = opener.open(req)

for cookie in cj:
   # print cj.extract_cookies
	 print cookie.value

	 
	 
# ###############################################################


url = "*202.38.180.2/userportal/newlogin.do"

data= { 
		"username":"XXXXXX",
		"password":"XXXXXX",
		"type":"2",
		"phone":"0",
		"fromTemplate":"1"
	}
	
headers = {
			"Host": "202.38.180.2",
			"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0",
			"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
			"Accept-Language": "en-US,en;q=0.5",
			"Accept-Encoding": "gzip, deflate",
			#"Referer": "*202.38.180.2/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F",
			"Referer":"file:///userportal/logout.do?svccat=1",
		#	"Cookie": cookie.value

	}	
r = requests.Session()
#test add

opener.addheaders.append(('Cookie', 'cookiename=cookie.value'))
f = opener.open("*202.38.180.2/userportal/?requesturi=*1.254.254.254/?N=1445493268368&ip=172.17.60.114&mac=XXXXXX:d6&nas=starlink&requestip=1.254.254.254&sc=fad8137fd7006f7f388ede89bbc0a63b")

print r.post("*202.38.180.2/userportal/?requesturi=*1.254.254.254/?N=1445493268368&ip=172.17.60.114&mac=eXXXXXX&nas=starlink&requestip=1.254.254.254&sc=fad8137fd7006f7f388ede89bbc0a63b").text

#print r.getresponse()

r.cookies.get_dict()

print r.post(url, data=data, headers = headers).text

for cookie in cj:
   # print cj.extract_cookies
	 print cookie.value
```

- - - Updated - - -


```
from urllib2 import Request, build_opener, HTTPCookieProcessor, HTTPHandler
import cookielib

#Create a CookieJar object to hold the cookies
cj = cookielib.CookieJar()
#Create an opener to open pages using the http protocol and to process cookies.
opener = build_opener(HTTPCookieProcessor(cj), HTTPHandler())

#create a request object to be used to get the page.

req = Request("*202.38.180.2/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F")

f = opener.open(req)

for cookie in cj:
   # print cj.extract_cookies
	 print cookie.value
```


```
[root@alarmpi ~]# python t.py
  File "t.py", line 17
    print cookie.value
               ^
SyntaxError: Missing parentheses in call to 'print'
```

did i miss any prerequisites?


----------



## Faun (Nov 4, 2015)

Install python 2.7. 

python 3 expects parenthesis in all print calls. your os is using python 3 to execute script.


----------



## Rajesh345 (Nov 4, 2015)

Faun said:


> Install python 2.7.
> 
> python 3 expects parenthesis in all print calls. your os is using python 3 to execute script.




```
#!/usr/bin/env pytho
import requests
import urllib2
from urllib2 import Request, build_opener, HTTPCookieProcessor, HTTPHandler
import cookielib
opener = urllib2.build_opener()

#Create a CookieJar object to hold the cookies
cj = cookielib.CookieJar()

#Create an opener to open pages using the http protocol and to process cookies.
opener = build_opener(HTTPCookieProcessor(cj), HTTPHandler())

#create a request object to be used to get the page.

req = Request("*202.38.180.2/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F")

f = opener.open(req)

for cookie in cj:
   # print cj.extract_cookies
	 print cookie.value

	 
	 
# ###############################################################


url = "*202.38.180.2/userportal/newlogin.do"

data= { 
		"username":"Abhishek15",
		"password":"123456",
		"type":"2",
		"phone":"0",
		"fromTemplate":"1"
	}
	
headers = {
			"Host": "202.38.180.2",
			"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0",
			"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
			"Accept-Language": "en-US,en;q=0.5",
			"Accept-Encoding": "gzip, deflate",
			#"Referer": "*202.38.180.2/userportal/login.do?requesturi=http%3A%2F%2F1.254.254.254%2F",
			"Referer":"file:///userportal/logout.do?svccat=1",
			"Cookie": cookie.value

	}	
r = requests.Session()
#test add

opener.addheaders.append(('Cookie', 'cookiename=cookie.value'))
f = opener.open("*202.38.180.2/userportal/?requesturi=*1.254.254.254/?N=1445493268368&ip=172.17.60.114&mac=e8:de:27:47:52:d6&nas=starlink&requestip=1.254.254.254&sc=fad8137fd7006f7f388ede89bbc0a63b")

print r.post("*202.38.180.2/userportal/?requesturi=*1.254.254.254/?N=1445493268368&ip=172.17.60.114&mac=e8:de:27:47:52:d6&nas=starlink&requestip=1.254.254.254&sc=fad8137fd7006f7f388ede89bbc0a63b").text

print r.getresponse()

r.cookies.get_dict()

print r.post(url, data=data, headers = headers).text

for cookie in cj:
   # print cj.extract_cookies
	 print cookie.value
```

[alarm@alarmpi ~]$ python2.7 login1.py
  File "login1.py", line 41
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:41.0) Gecko/20100101
                                                                               ^
SyntaxError: EOL while scanning string literal


----------



## Faun (Nov 4, 2015)

can you upload the file on dropbox ?


----------



## Rajesh345 (Nov 5, 2015)

Faun said:


> can you upload the file on dropbox ?



*drive.google.com/file/d/0B7Dzp2x1VDWCRGNUV2taTk14SE0/view?usp=sharing

currently in office , i will confirm this is the latest backup of the python script when i reach home,  thank you again

- - - Updated - - -

I reinstalled 2015-05-05-raspbian-wheezy

and installed transmission and pyload also and ran the above file 



```
root@raspberrypi:/# python test01.py
  File "test01.py", line 22
    print cookie.value
    ^
IndentationError: unexpected indent
root@raspberrypi:/#
```


```
root@raspberrypi:/# python2.6 test01.py
  File "test01.py", line 22
    print cookie.value
    ^
IndentationError: unexpected indent
```



```
root@raspberrypi:/# python3.2 test01.py
  File "test01.py", line 21
    print cj.extract_cookies
           ^
SyntaxError: invalid syntax
root@raspberrypi:/#
```


same code running form windows ran with no issue 

Output from windows

```
957CA64CCDE1B83D2B4F3BDAABB3809D


 











<html>

	<head>

	<title>Powered by Inventum</title>

		<SCRIPT>

			function moveToLogin() {

                                setTimeout("loadForm()",500);

            }

			function loadForm(){

				document.forms[0].action="login.do?requesturi=http%3A%2F%2F1.254.254.254%2F%3FN%3D1445493268368";

				document.forms[0].method="post";

				document.forms[0].submit();

			}

		</SCRIPT>	

	</head>

	<body onload="moveToLogin();">

		<FORM>

			Loading the login page...

		</FORM>

	</body>

</html>


	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

	<html>
	<head>
	  <title>New Customer Login Page</title>
	  <meta content="Evrsoft First Page" name="GENERATOR">
	  <meta http-equiv="content-type" content="text/html; charset=us-ascii">
	  
	  <script language="JavaScript" src="pages/js/common.js"></script>
	  <script type="text/javascript">
	  function onSubmit(){
		  
		  if(document.forms[0].username.value==""){
				alert("Please enter Username");
				document.forms[0].username.focus();
				return false;
				
			}else if(document.forms[0].password.value==""){
					alert("Please enter Password");
					document.forms[0].password.focus();
					return false;
			}
		if (document.forms[0].rememberme.checked)
				{	
					createCookie('nasusername',document.forms[0].username.value,2);
					createCookie('type',document.forms[0].type.value,2);
					createCookie('nasrememberme',1,2);
							
				}
				else
				{
					eraseCookie('nasusername');
					eraseCookie('type');
					eraseCookie('nasrememberme');
				}
				
				//	document.forms[0].action = "newlogin.do?phone=0";
				//	document.forms[0].method = "post";
				//	document.forms[0].submit();
				//	return true;
				
	  }
	   function go_now()
	   {
	   	window.open("*1.254.254.254/?N=1445493268368","RequestIP");
		   }

	function bodyOnload()
	{
	setTimeout("go_now()",2000); 
                        document.forms[0].type.selectedIndex = "0";
			if (document.forms[0].username.value.length ==0)
				document.forms[0].username.focus();
			else
				document.forms[0].password.focus();
			
			
	}
	function getSettings()
	{
		
	   var usrname=readCookie('nasusername');
	   var dom=readCookie('type');
	   document.forms[0].username.value = usrname;
	   document.forms[0].type.value = dom;
	   document.forms[0].password.value="";
	   if(usrname==null){
			document.forms[0].username.value = "";
			document.forms[0].type.value = "";
			document.forms[0].rememberme.checked=false;
			document.forms[0].username.focus();
		}
		else{
			if(usrname.length<=0)
				document.forms[0].rememberme.checked=false;
			else
				document.forms[0].rememberme.checked=true;
			document.forms[0].password.focus();
		}
		
	
			
					
						
			var dt = '11/25/2015 20:08:00';
			var currentdate = new Date();
			var expirydate = new Date(dt);
			var month = expirydate.getMonth();
			var date = expirydate.getDate();


			
			var ex_second =( expirydate.getTime() - currentdate.getTime())/1000;
		
			if(ex_second<=86400*7)
			{
				var k;
				for(k=7;k>=1;k--) 
				{
					if(ex_second<=86400*k && ex_second>86400*(k-1))
					{                                       
									  
					alert("Dear Customer, your broadband subscription is going to expire within  "+k+"day(s), pls recharge your  internet ID to enjoy uninterrupted services.");
										
					}
				}
			}
				}
				

	function createCookie(name,value,days)
	{
	   if (days) 
		{
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
	  else
		var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
	}
		
	function readCookie(name)
	{
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) 
		{
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}


	function eraseCookie(name)
	{
		createCookie(name,"",-1);
	}
	
	  </script>
		
	  <style>
	  body{font-family:Arial, Helvetica, sans-serif;}
	  .smalltext {
	color:#333333;
	font-family:Verdana,Arial,Helvetica;
	font-size:11px;
	text-align:left;
	}
	.tborder {
	background-color:#FFFFFF;
	border:1px solid #6393DF;
	color:#000000;
	}</style>

	 
	</head>

	<body   onload="getSettings(); bodyOnload();" >
<!-- *1.254.254.254/?N=1445493268368 -->

	<form action="newlogin.do" method="post" onsubmit="return onSubmit();">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
				<tr>
                    <td><img src="/userportal/pages/images/airwire.jpg" ></td>
                </tr>
						 <tr>
						<td  align="center" valign="top"> 
							<table border="0" cellpadding="0" cellspacing="0" width="100%">
								<tr>
									<td bgcolor="#3894e5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#83bff5" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
								<tr>
									<td bgcolor="#c3e3ff" height="2"><img src="pages/images/space_002.gif" height="2" width="1"></td>
								</tr>
							</table>  
	 

	  <br>
	  
	  <div style="float:left; padding:5px 0px; background-color:#6d9de9; border:1px solid #3e79d7; font-size:16px; font-weight:bold; width:288px; margin-left:3px;">
    <a style="color:#ffffff;" href="/userportal/logout.do?svccat=1">Click here to Logout</a></td>
	  </div>
	  
	  <div align="left">

		<table width="600"><tr><td width="570">
		  <table style="WIDTH: 80%; HEIGHT: 130px; TEXT-ALIGN: center" class="tborder" cellspacing="2" cellpadding="2" border="0">
			<tbody>
			<tr><td colspan="3" style="background-color:#6D9DE9; color:#ffffff; font-size:14px; font-weight:bold;" align="left">Login</td></tr>
			  <tr>
				<td class="smalltext" width="40%" align="left">Username</td>
				<td width="10%"></td>
				<td width="50%" align="left"><input type="text" name="username"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left"> Password</td>
				<td></td>
				<td align="left"><input type="password" name="password"></td>
			  </tr>
			  <tr>
				<td class="smalltext" align="left">Service Type</td>
				<td></td>
				<td align="left"><select name="type">
				  
							<option value="1" >Account</option>
						</select></td>
			  </tr>          
			  <tr>
				<td class="smalltext" align="left">Remember me</td>
				<td></td>
				<td align="left"><input type="checkbox" name="rememberme" id="rememberme"></td>
			  </tr>

			  <tr> 
				<td></td>
				<td></td>         
				<td align="left"><input type="submit" value="Submit"></td>
			  </tr>

			</tbody>

		 </table><input type="hidden" value="0" name="phone"> <input type="hidden" value="1" name="fromTemplate"></td><td width="606">

			</td></tr></table>

	</div> 

	<tr>
    <td>
			<table width="100%">
            <tr>
	<td width="766" height="103">
				<div style="color: #336699; font-size: 12px; font-weight:bold; text-align:center;"></a>&copy;  

NORTH EAST DATA NETWORK PVT LTD </div>
			</td>
		</tr>
	</table>
</td>
</tr>
</table>
		</form>
	</body>
	</html>
		

957CA64CCDE1B83D2B4F3BDAABB3809D
```


----------



## Faun (Nov 5, 2015)

Python is an indented language. Instead of brackets, indents define the scopes.


post the latest file. I can't see which issue is relevant now.


----------



## Rajesh345 (Nov 5, 2015)

i moded same script for office internet and its working  kept in task schedule 
will check home broadband script in detail today night and update you

- - - Updated - - -

thank you for all the tips about python lang  u gave that day  i fixed it , thank you again


----------

