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
can you upload the file on dropbox ?
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:/#
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>©
NORTH EAST DATA NETWORK PVT LTD </div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
957CA64CCDE1B83D2B4F3BDAABB3809D