I am getting an attribute error...Group not found on cookie = m.group(1)

Can any one fix my code here?

#!usr/bin/python

import re
import urllib
import urllib2

def MassVote(first_number, last_number, email1, email3, password, community_id, join = False, unjoin = False):
	def curl(url, cookie = None, get_header = False, fields = None):
		print url
		req = urllib2.Request(url)
		if cookie:
			req.add_header('Set-Cookie', cookie)
		if fields:
			req.set_data(fields)
		r = urllib2.urlopen(req)
		if get_header:
			c = str(r.info())
		else:
			c = r.read()
		return c
	
	o = 'http://www.orkut.com/'
	g = "https://www.google.com/accounts/ClientLogin?Email="

	for n in range(first_number, last_number+1):

		l = email1
		z = email3
		p = password
		mail = email1+str(n)+email3
		
		r = curl(g+mail+"&Passwd=hellyeah&skipvpage=true&service=orkut")
		m = re.search("Auth=(.*)",r,re.I)
		auth = m.group(1)

		r = curl(o+"RedirLogin.aspx?auth=auth", get_header = True)
		m = re.match('orkut_state=ORKUTPREF.*',r,re.I)
		cookie = m.group(0)

		r = curl(o+"scrapbook.aspx", cookie)
		m = re.findall("value\=\"([^\"]{28,32})\"",r,re.I)
		postsig = "POST_TOKEN="+m[0].group(1)+"&signature="+urllib.quote_plus(m[1].group(1))

		if join:
			jin  = "http://www.orkut.com/CommunityJoin.aspx?community_id="+community_id
			PTSG = postsig+"&Action.join"
			r = curl(jin,cookie,True,PTSG)

			print "Community joined by <b>"+email+"</b><br>"

		if unjoin:
			unjin  = "http://www.orkut.com/CommunityUnjoin.aspx?community_id="+community_id
			PTSG = postsig+"&Action.unjoin"
			r = curl(unjin,cookie,True,PTSG)

			print "Community unjoined by <b>"+email+"</b><br>"

def test():
	MassVote(1, 5, 'gamesan', '@yahoo.com', 'hellyeah', '48783497', True, False)
	
if __name__=='__main__':
	test()

If your regex doesn't match anything it returns a None, which gets stored to m. You should have a check before accessing m.groups by saying if m:

I translated my php code to python.. my php code is working here:

$r = curl($g.$email1.$n.$email3."&Passwd=$p&skipvpage=true&service=orkut",1,0,0,null);
preg_match_all("/Auth=(.*)/i",$r,$r);
$auth=$r[1][0];

$r = curl($o."RedirLogin.aspx?auth=$auth",1,0,1,null);
preg_match_all("/orkut_state=ORKUTPREF.*/i",$r,$r);
$cookie=$r[0][0];

Can anyone translate it right?

$r = curl($o."RedirLogin.aspx?auth=$auth",1,0,1,null);

Right here. In your python script you have 'auth=auth'.

It should be r = curl(o+"RedirLogin.aspx?auth=%s" % auth, get_header = True)

Right here. In your python script you have 'auth=auth'.

It should be r = curl(o+"RedirLogin.aspx?auth=%s" % auth, get_header = True)

Yes it worked but i am still getting that error:

cookie = m.group(0)
AttributeError: 'NoneType' object has no attribute 'group'

That is because like I said: if the regex doesn't match anything it returns a None. Try checking your code line by line in an interpreter to see what's happening I got to the line that says r = curl(o+'RedirLogin.aspx?auth=%s' % auth, get_header=True) . When you check the value of 'r' you see that there is no orkut_state= anything.

That is because like I said: if the regex doesn't match anything it returns a None. Try checking your code line by line in an interpreter to see what's happening I got to the line that says r = curl(o+'RedirLogin.aspx?auth=%s' % auth, get_header=True) . When you check the value of 'r' you see that there is no orkut_state= anything.

Yes you are right at ur place. But i think that is needed to store cookies... And i m translating this from php.. how come orkut_state= is there and is working... So thats y i put this orkut_state= in python too.. i will show u my entire php code.. u might get some idea..

PHP code:

<?php
function MassVote() {
function curl($a,$b,$c,$d,$e){
   $ch = curl_init();
      curl_setopt_array($ch,
         array(
            CURLOPT_URL => $a,
            CURLOPT_RETURNTRANSFER => $b,
            CURLOPT_COOKIE => $c,
            CURLOPT_HEADER => $d,
            CURLOPT_NOBODY => $d,
            CURLOPT_CUSTOMREQUEST => ($e)?"POST":"GET",
            CURLOPT_POSTFIELDS => $e
         )
      );
   $g = curl_exec($ch);
   curl_close($ch);
   return $g;
}

$number = range($_POST['nf'],$_POST['nl']);

$email1 = $_POST['email1'];
$email3 = $_POST['email3'];

$senha = $_POST['senha'];

$o = "http://www.orkut.com/";
$g = "https://www.google.com/accounts/ClientLogin?Email=";
$cmm = $_POST['cmm'];


for($i=0;$i<count($number);$i++){

$n = $number[$i];

$l = $email1;
$z = $email3;
$p = $senha;

$r = curl($g.$email1.$n.$email3."&Passwd=$p&skipvpage=true&service=orkut",1,0,0,null);
preg_match_all("/Auth=(.*)/i",$r,$r);
$auth=$r[1][0];

$r = curl($o."RedirLogin.aspx?auth=$auth",1,0,1,null);
preg_match_all("/orkut_state=ORKUTPREF.*/i",$r,$r);
$cookie=$r[0][0];

$r = curl($o."scrapbook.aspx",1,$cookie,0,null);
preg_match_all("/value\=\"([^\"]{28,32})\"/i",$r,$r);
$postsig= "POST_TOKEN=".$r[1][0]."&signature=".rawurlencode($r[1][1]);

$sscrap = "http://www.orkut.com/Scrapbook.aspx?uid=12479430764362367628";
$r = curl($sscrap,1,$cookie,1,$postsig."&scrapText=[b]Zeroburn rox! [:P] using Sb flooder&Action.submit=1");

$jin  = "http://www.orkut.com/CommunityJoin.aspx?cmm=".$cmm;
$PTSG = $postsig."&Action.join";
$r = curl($jin,1,$cookie,1,$PTSG);

print_r("Community joined by <b>".$email1.$n.$email3."</b><br>");



flush();

};
}
    if(isset($_POST['cmm'])){
     MassVote();
    }
?>

I hope u have got some idea.. that it needs cookies to go to any page...

I would imagine that the problem is with the python version of curl that you wrote. Perhaps you should try looking into PycURL.

I would imagine that the problem is with the python version of curl that you wrote. Perhaps you should try looking into PycURL.

Well thanks for helping.

One more thing. Now i have the cookies.

cookies = "somecookies"
r = curl("http://www.orkut.com/Scrapbook.aspx", cookie)

We need to login before we can view this page...http://www.orkut.com/Scrapbook.aspx

So i m adding variable at the end of this line.

r = curl("http://www.orkut.com/Scrapbook.aspx", cookie)

But it doesn't gets logged in. it simply shows the login page.. Can u tell me how to log in.. after i m having cookies..

This article has been dead for over six months. Start a new discussion instead.