Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Python + urllib2


ghost's Avatar
0 0

I'm working on the timed challenges with python but I am running into a few pretty big problems. This question isn't directly related to any of the timed problems so I posted hereā€¦

I have a python script that should solve timed1 but my internet connection over is MUCH MUCH too slow and there is no chance of finding a faster one for six months so I tried to put the python script on my website that is hosted in the states.

I have a very simple script that will send my cookie info and fetch the main HBH page. It works fine on my laptop but when I run it on the webserver I keep getting 302 errors thrown back. You can see it at http://www.mrfirebug.com/hellbound/timed/timed.py but I doubt my phpsessionid will stay valid for much longer. It will probably be broken when the vast majority of people visit.

My laptop is running XP and the server is running a variant of linux. I don't think the OS variance has anything to do with my problem since I'm not using any OS-specific calls.

Something with the remote server + HBH + my code doesn't seem to be mixing well. Does anyone have any ideas? I can pm the code if you want to take a look but I don't want to post here in case there are any unintentional/inadvertent spoilers.


ghost's Avatar
0 0

302 isn't an error, it's a redirect. HBH's cookies are IP based, if it doesn't match (which in your case it won't) then it won't recognize you. It's that simple.


ynori7's Avatar
Future Emperor of Earth
0 0

Indeed, have your script login with your username and password rather than just using a premade cookie value.

opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders.append(('User-agent', 'Mozilla/4.0'))
opener.addheaders.append( ('Referer', 'http://www.hellboundhackers.org/index.php') )
 
login_data = urllib.urlencode({'user_name' : 'username',
                               'user_pass' : 'password',
                               'login' : 'Login'
                               })
 
resp = opener.open('http://www.hellboundhackers.org/index.php', login_data)
resp.close()```
That should fix it.

ghost's Avatar
0 0

Thank you. That was exactly what I needed.