not logging into the site, help anyone?

import time
import datetime
import urllib2
import cookielib
import os
import sys
import socket
import threading
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders  = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0)  Gecko/20100101 Firefox/13.0.1         ID:20120614114901')]
GOD_CHECK_TIME = 0.2 # The speed at which it rechecks for a raid in the room
FORMER_ID = "ACCOUNT ID"     # Form account ID
CAST_SIN = False   # True or False to cast a SiN
SIN_ID = ""        # Optional if you set CAST_SIN to True
rg_sess_id = ""    # From typpo
username = "USERNAME"
password = "PASSWORD"
chars = (["ID", "ID", "ID"])
#global editables, dont touch these
RAID_ID = ""
_startTime =
_finishTime =
#anti-lag-opener, alo=get alo2=post
def alo(url):
    lagsafe = 1
    while lagsafe == 1:
            site =
            lagsafe = 0
        except IOError:
            print "URLError: Site not loading. Retrying..."
    return site
def alo2(url, pData):
    lagsafe = 1
    while lagsafe == 1:
            site =, pData)
            lagsafe = 0
        except IOError:
            print "URLError: Site not loading. Retrying..."
    return site
# Print a message with timestamp
def msg(out):
    thetime = time.strftime("[%H:%M:%S]", time.localtime(time.time()))
    message = thetime + " " + out
    print message
    return message
def getCharName(src):
    charName = "Unknown"
        charName = src.split('" selected>')[1].split('</option>')[0]
        msg("Could not retrieve character name.")
    return charName
# Get the substring of a string,
# iB("<hello> world </hello>", "<hello>", "</hello>")
# The above would return "world"
def iB(src, start, end):
        return src.split(start)[1].split(end)[0]
    except IndexError:
        msg("Could not retrieve the inbetween value.")
def formRaid(formerID):
    one = 1
    while one == 1:
            global _startTime
            _startTime =
            srcworld = alo("" + formerID + '&serverid=2').read()
            # raidicondead.png wasnt found so god must be spawned
            raidLink = srcworld.split("formraid.php?target=")[1].split('\\">')[0]
            print ""
            msg("***Raid spotted, forming raid.")
            formpage = alo("" + raidLink).read()
            codeID = formpage.split('codeid" value="')[1].split('">')[0]
            Form = alo2("" + raidLink, "target=" + raidLink + "&codeid=" + codeID + "&formtime=3&submit=Launch!").read()
            global RAID_ID, RAID_NAME
            RAID_ID = getRaidID(Form)
            RAID_NAME = getRaidName(Form)
            msg("***" + RAID_NAME + " Formed.")
            one = 0
            return True
        except IndexError:
            msg("God not spawned.")
def getRaidID(src):
    #raids = alo("")
    #srcraids =
        return iB(src, "joinraid.php?raidid=", "&")
    except IndexError:
        msg("Couldn't retrieve raid ID")
        return False
def getRaidName(src):
        return iB(src, "<div ONMOUSEOVER=\"statspopup(event,'<b>", "</b>')\" ONMOUSEOUT=\"kill()\">")
    except IndexError:
        msg("Couldn't retrieve raid name")
        return False
def launchRaid(launchURL):
    x = 1
    while x == 1:
            launch = alo(launchURL).read()
            if "Your raid will launch shortly" in launch:
                msg("RAID LAUNCHED!")
                global _finishTime
                _finishTime =
                x = 0
                return True
        except IndexError:
            x = 1
def createReport(raidTime):
    r = open("numero.txt", "a")
    r.write("Raid launched at " + time.strftime("[%H:%M:%S]",  time.localtime(time.time())) + " \nThe raid took  "+str(raidTime.seconds)+" seconds.")
    return True
#loginrpg = alo("" + rg_sess_id + "&serverid=2&suid="+FORMER_ID)
loginrpg = alo2("", "login_username=" + username + "&login_password=" + password +    "&serverid=2&suid="+FORMER_ID)
msg("Logged in RGA\n")
class ThreadClass(threading.Thread):
    def __init__(self, char):
        self.char = char
    def run(self):
        join = alo2(''+RAID_ID+'&suid='+self.char+'&serverid=2', "join=1").read()
        if "error" in join:
            x = 1
            while x == 1:
               join = alo2(''+RAID_ID+'&suid='+self.char+'&serverid=2', "join=1").read()
               if "Please click" in join:
                   x = 0
        msg("Joined character: " + getCharName(join))
for i in range(len(chars)):
  t = ThreadClass(chars[i])
# Cast SiN
if CAST_SIN == True:
    cast = alo2(""+SIN_ID, "castskillid=3015&cast=Cast+Skill")
    msg("Casted Strength in Numbers on " + getCharName(cast))
launchURL = '' + RAID_ID + '&suid=' + FORMER_ID +   '&serverid=2&launchraid=yes&x=141&y=36'
tTime = _finishTime - _startTime
msg("TOTAL RAID TIME: " + str(tTime.seconds) + " seconds.\n") 
keepChecking = 0

(edited to fix code blocks -hansel)

Hello - could you paste your code indented by four spaces, and with ':::python' at the start as this will make it much easier to read

Hi Crosby,

I've seen this code before, I understand other people are running it successfully. What is the actual error message (normally called a traceback) that you are seeing?

it doesn't give an error it runs fine on my computer but when i use it on pythonanywhere it won't login to the account. The site it's trying to connect to locks the IP out for 15 mins if they enter an incorrect Username/Password 3x, i think this is the problem does anyone know of a way round this?

It must be giving an error somewhere? If the problem is the site itself rejecting your login attempts as being incorrect then there really isn't much we can do about it. We have no control over whether or not your login credentials are being accepted.

However, I don't think this is the case. How are you running this script? It must provide some kind of output / stacktrace on failure.



The code runs fine, outwar itself is rejecting it, i believe another user is on purposely entering the details incorrectly through pythonanywhere i could prove this much easier by letting you connect to me through teamviewer and showing you this

Hi Crosby, if you want me to have a look then you could share the PythonAnywhere console that you are using to wrong this script with me. Just enter the username 'hansel' in the 'Share with others' dialog when you're running this.

ok i will share it but to you iit will look as though it's working fine but in actual fact its not logged in because pythonanywheres IP is logged out of Outwar because someone is inputting the incorrect information on purpose so other people can't log in vis pythonanywheres IP address, hence i want to know if there is a way around this?

Okay, I've had a look at your console. I see an UrlError being raised every couple of seconds. If someone else is maliciously entering your username / incorrect password in order to block your access then it sounds like something you would need to sort out with them or with OutWar itself. Have you checked with OutWar that it is okay to run these kind of scripts against their service?

the problem itself lies in everyone who uses pythonanywhere having the same IP Address, therefore i have cancelled my subscription. Unless you know of anyway around this IP restriction problem then i will resume my subscription

Yes I do know of methods to hide the originating IP address of requests. Using a series of proxies is probably the easiest way. However we have no interest in doing that.

But hey, maybe some people in the PythonAnywhere community might see this as an opportunity to make a bit of passive income and want to set something up for you?