Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #63766

Re: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor'

References <9e7e031f-b6db-43fc-84d2-ef68916ec756@googlegroups.com>
Date 2014-01-12 23:42 +1100
Subject Re: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor'
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.5365.1389530545.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Jan 12, 2014 at 11:17 PM, KMeans Algorithm <bilbaow@gmail.com> wrote:
> What am I doing wrong? Thank you very much.

I can't say what's actually wrong, but I have a few ideas for getting
more information out of the system...

> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())

You don't do anything with this opener - could you have a cookie problem?

> req = urllib2.Request(url, login)
>
> But I get a "404" error (Not Found). The page "https://www.mysite.com/loginpage" does exist (note please the httpS, since I'm not sure if this the key of my problem).
>
> If I try with
>
> -------
> resp = urllib2.urlopen(url)
> --------
> (with no 'login' data), it works ok but, obviously, I'm not logged in.

Note that adding a data parameter changes the request from a GET to a
POST. I'd normally expect the server to respond 404 to both or
neither, but it's theoretically possible.

It's also possible that you're getting redirected, and that (maybe
because cookies aren't being retained??) the destination is 404. I'm
not familiar with urllib2, but if you get a response object back, you
can call .geturl() on it - no idea how that goes with HTTP errors,
though.

You may want to look at the exception's .reason attribute - might be
more informative than .code.

As a last resort, try firing up Wireshark or something and watch
exactly what gets sent and received. I went looking through the docs
for a "verbose" mode or a "debug" setting but can't find one - that'd
be ideal if it exists, though.

Hope that's of at least some help!

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' KMeans Algorithm <bilbaow@gmail.com> - 2014-01-12 04:17 -0800
  Re: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' Chris Angelico <rosuav@gmail.com> - 2014-01-12 23:42 +1100
  Re: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' Chris Angelico <rosuav@gmail.com> - 2014-01-12 23:44 +1100
  Re: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' xDog Walker <thudfoo@gmail.com> - 2014-01-12 07:17 -0800
  Re: Python: 404 Error when trying to login a webpage by using 'urllib' and 'HTTPCookieProcessor' Terry Reedy <tjreedy@udel.edu> - 2014-01-12 15:51 -0500

csiph-web