News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Trying to create an AI robot

Started by god0fgod, June 30, 2009, 12:20:54 PM

Previous topic - Next topic

god0fgod

Sorry if this is the wrong place to post.

I want to create a robot that can automatically post on SMF and which will use chatbots such as Alice to talk to people on forums. I'm doing this as a python script. It's just an interesting experiment really. If it works well I'll let others play with it as well if they want to.

I was wondering if anyone would know what I'm doing wrong with trying to login automatically.

With httplib I use the headers and post information:

params = urllib.urlencode({'user': username, 'passwrd': password, 'cookieneverexp': 'on',"hashpasswrd":''})
headers = {"Content-Type": "application/x-www-form-urlencoded","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","User-Agent": "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050512 Firefox",'Cookie': "PHPSESSID=" + phpsessid,"Referer": "http://forums.tsmusicbox.com/index.php?PHPSESSID=" + phpsessid + "&action=login","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host": "forums.tsmusicbox.com","Keep-Alive": "300","Connection": "keep-alive","Accept-Language": "en-gb"}


But I get An Error Has Occurred in the response.

My code has another problem with displaying the data at the moment as well but that isn't going to cause this problem. Here is the code for anyone who knows python well:

import httplib, urllib, time
class SMF_login:
def __init__(self,website,forums_path,username,password, tries):
fine = False
self.conn = None
tries += 1
self.conn = httplib.HTTPConnection(website)
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain","User-Agent": "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050512 Firefox","Referer": "http://www.crytekuk.info","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host": "forums.tsmusicbox.com","Keep-Alive": "300","Connection": "keep-alive","Accept-Language": "en-gb"}
self.conn.request("GET", "/","",headers)
response = self.conn.getresponse()
cookies_set = response.getheader("Set-Cookie")
done = False
id_pos = 10
phpsessid = ""
while(not done):
if(cookies_set[cookies_set.find("PHPSESSID") + id_pos] != ";"):
phpsessid += cookies_set[cookies_set.find("PHPSESSID")+id_pos]
id_pos = id_pos + 1
else:
done = True
print phpsessid + " " +cookies_set
while(not fine):
tries += -1
self.conn.close()
self.conn = httplib.HTTPConnection(website)
params = urllib.urlencode({'user': username, 'passwrd': password, 'cookieneverexp': 'on',"hashpasswrd":''})
headers = {"Content-Type": "application/x-www-form-urlencoded","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","User-Agent": "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050512 Firefox",'Cookie': "PHPSESSID=" + phpsessid,"Referer": "http://forums.tsmusicbox.com/index.php?PHPSESSID=" + phpsessid + "&action=login","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host": "forums.tsmusicbox.com","Keep-Alive": "300","Connection": "keep-alive","Accept-Language": "en-gb"}
print headers
self.conn.request("POST", forums_path + "index.php?action=login2", params, headers)
response = self.conn.getresponse()
if(response.status == 200):
data = response.read()
print "DATA-" + data + "-DATA"
if(data.find('That username does not exist.') == -1 and data.find('An Error Has Occurred') == -1):
fine = True
print "Logged in as " + username + ":"
else:
print "Login fail?"
print data
pos = data.find('will have to wait about')
if(pos != -1):
space = False
flood = ""
pos_extra = 24
while(not space):
if(data[(pos + pos_extra)] != " "):
flood += data[pos + pos_extra]
pos_extra = pos_extra + 1
else:
space = True
print "Waiting " + flood + " Seconds"
print response.getheader("Set-Cookie")
time.sleep(int(flood))
else:
print response.status + " " + response.reason
if tries == 0 and not fine:
print "FAILED LOGIN FOR " + username
break

alice = SMF_login("***********","/","Alice",********",10)
while(1):
pass


If anyone can help, I thank you plenty.

god0fgod

Thank you for the reply.

I looked at what firefox sends with the Tamper Data plugin. I then sent the same cookie information with the correct phpsessid, so I don't see how the header information can be wrong. It only sends the PHPSESSID cookie and nothing else because the smf software doesn't give any other cookie it seems. Once I get past the login I'll look at the other cookie. I think the other cookie is for remembering the user right?

god0fgod

Hmmm, then what must be causing it?

What is the list of things that could cause this "An Error Has Occurred" to appear? What file could I look at for answers?

god0fgod

#3
I can't produce any errors in the error log.

Well, I'm going to try and fix the python error where the data doesn't exist at "print "DATA-" + data + "-DATA"" It's a completely empty string.

It only shows when I force the script into the else statement around that part. That's when I get the error.

Once I fix this, it will be easier.

import httplib, urllib, time
'''alice pass - '''
class SMF_login:
def __init__(self,website,forums_path,username,password, tries):
self.logged_in = False
self.website = website
self.forums_path = forums_path
fine = False
self.conn = None
self.conn = httplib.HTTPConnection(website)
headers = {"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain","User-Agent": "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050512 Firefox","Referer": "http://www.crytekuk.info","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host": website,"Keep-Alive": "300","Connection": "keep-alive","Accept-Language": "en-gb"}
self.conn.request("GET", self.forums_path,"",headers)
response = self.conn.getresponse()
print response.read()
cookies_set = response.getheader("Set-Cookie")
done = False
id_pos = 10
self.phpsessid = ""
while(not done):
try:
if(cookies_set[cookies_set.find("PHPSESSID") + id_pos] != ";"):
self.phpsessid += cookies_set[cookies_set.find("PHPSESSID")+id_pos]
id_pos = id_pos + 1
else:
done = True
except AttributeError:
print "No Cookies"
return
print self.phpsessid + " " +cookies_set
time.sleep(1)
while(tries >= 0):
tries += -1
self.conn.close()
self.conn = httplib.HTTPConnection(website)
params = urllib.urlencode({'user': username, 'passwrd': password, 'cookieneverexp': 'on',"hashpasswrd":''})
headers = {"Content-Type": "application/x-www-form-urlencoded","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","User-Agent": "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.6) Gecko/20050512 Firefox",'Cookie': "PHPSESSID=" + self.phpsessid,"Referer": "http://forums.tsmusicbox.com/index.php?PHPSESSID=" + self.phpsessid + "&action=login","Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Host": website,"Keep-Alive": "300","Connection": "keep-alive","Accept-Language": "en-gb"}
print headers
self.conn.request("POST", forums_path + "index.php?action=login2&PHPSESSID=" + self.phpsessid, params, headers)
response = self.conn.getresponse()
if(response.status == 200):
data = response.read()
print "DATA-" + data + "-DATA"            '''HERE'''
if(data.find('That username does not exist.') == -1 and data.find('An Error Has Occurred') == -1):
print "Logged in as " + username + ":"
self.logged_in = True
time.sleep(1)
break
else:
print "Login fail?"
print data
pos = data.find('will have to wait about')
if(pos != -1):
space = False
flood = ""
pos_extra = 24
while(not space):
if(data[(pos + pos_extra)] != " "):
flood += data[pos + pos_extra]
pos_extra = pos_extra + 1
else:
space = True
print "Waiting " + flood + " Seconds"
print response.getheader("Set-Cookie")
time.sleep(int(flood))
else:
print response.status + " " + response.reason
if tries == 0 and not fine:
print "FAILED LOGIN FOR " + username
self.logged_in = False
break
def talk(self,ai,interest_chance,read_time,write_time):
if(self.logged_in == True):
cancel = False
while(cancel == False):
self.conn.request("GET", self.forums_path + "index.php?action=unread;all;start=0")
response = self.conn.getresponse()
if(response.status == 200):
data = response.read()
print data
if(data.find('Only registered members are allowed to access this section') == -1):
print "Whoop!"
else:
print ":("
break
alice = SMF_login("www.godofgod.co.uk","/smf_test/","Alice","",10)
alice.talk("alice",64,32,170)
while(1):
pass

rapvideosguy

Is your AI robot going to develop feelings and try to take over west manhattan?

Advertisement: