Timed 2, POST not submitting (Python)
I managed to get the first challenge to work in essentially the same way I'm trying to do this one, but when my program submits the answer, I just get back the source of the /challenges/timed/timed2/index.php file, including a new hash. is there someone I can PM for help, because I don't think I can post any of my code without giving a spoiler.
I'm kind of hoping to get my code working, I've already started over from scratch once, hoping it was something I would notice if I typed it again. Besides that, I wanted an opportunity to learn more about handling internet access in python. While using your code would be easier, it would rob me of a chance to learn more.
You should check out this: http://www.hellboundhackers.org/articles/904-Using-Python-for-timed-challenges..html;)
elmiguel wrote: You should check out this: http://www.hellboundhackers.org/articles/904-Using-Python-for-timed-challenges..html;) That was the first place I checked when I started having problems. some of the code mentioned is just wrong, for instance urllib2 is not callable, I had to use urllib2.Request. other than that, I'm going exactly by that article and it's not working. what I'm confused about is I'm not getting "YOU MUST BE LOGGED IN TO PLAY" and I'm not getting "No off site posts" I'm just getting the page back. My code is just completely ignoring my POST request. I tried techb's code and as is it works, but when I try to code only the parts that seem to be doing something, it goes back to ignoring my POST data.
As I know not one iota about Python networking…
I'd say the easiest way to debug this would be to just run a quick packet sniff along side running the script to make sure the HTTP request is not mal-formed.
- Take a look at the stream and see whether there was a HTTP response/TCP close whatever.
- Then, load up your browser of preference, load the page and compare the two requests side by side.
Often a HTTP server will reject, for example: i) A HTTP/1.0 requests since it's a bit out dated and only allow HTTP/1.1 - not entriely accurate but hey… ii) If they appear, on first glance, to be practially the same, check your line feeds very carefully, look at the Hex dump if necessary. At the end of a POST request with the string of POSTed varibles, there shouldn't be another CRLF - this sometimes causes problems in a HTTP request too (from what I can remember).
Hope this helps you find the error…
Jim,
That article was written when Python 2.6 was new. There could be some changes on how the module is called in later versions. But as techb states: it is all about how you handle your cookies, and you need to pass your user agent like this: User-agent: Mozilla, or whatever, just make sure its User-agent not User-Agent as the latter is for exact specification of the agent as the preceding is for custom agents. Also, make sure you add the referrer to your request.