Re: urllib2 and HTTP 302

Discussion in 'Python' started by John J. Lee, Jun 1, 2006.

  1. John J. Lee

    John J. Lee Guest

    Laszlo Nagy <> writes:
    [...]
    > how can I return the redirection URL?
    > I tried to get this information from the exception but I could not. Is
    > it possible to read it from the openerdirector?
    > Any suggestions?
    >
    >
    > try:
    > self.post_multipart(
    > url,
    > [('uploadType','Inventory')],
    > [('uploadFileName','inv.txt',fdata)]
    > )
    > except urllib2.HTTPError, e:
    > if e.code == 302:
    > return "I would like to get the URL to be redirected
    > to...."
    > else:
    > raise


    redirected_url = e.geturl()


    John
    John J. Lee, Jun 1, 2006
    #1
    1. Advertising

  2. John J. Lee

    John J. Lee Guest

    (John J. Lee) writes:

    > Laszlo Nagy <> writes:
    > [...]
    > > how can I return the redirection URL?
    > > I tried to get this information from the exception but I could not. Is
    > > it possible to read it from the openerdirector?
    > > Any suggestions?
    > >
    > >
    > > try:
    > > self.post_multipart(
    > > url,
    > > [('uploadType','Inventory')],
    > > [('uploadFileName','inv.txt',fdata)]
    > > )
    > > except urllib2.HTTPError, e:
    > > if e.code == 302:
    > > return "I would like to get the URL to be redirected
    > > to...."
    > > else:
    > > raise

    >
    > redirected_url = e.geturl()


    Sorry, didn't read that properly.

    If your OpenerDirector instance has an HTTPRedirectHandler, you should
    be able to get the final redirected URL the way I said (using
    ..geturl()). If it doesn't (which I assume is true in your case -- why
    else would you be checking for a 302 status), well, you just have to
    do exactly the same thing that HTTPRedirectHandler does :) Use the
    source luke.


    John
    John J. Lee, Jun 5, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hendy
    Replies:
    0
    Views:
    747
    hendy
    Dec 20, 2005
  2. =?ISO-8859-1?Q?Eino_M=E4kitalo?=

    urllib2 and Set-Cookie with "302 Moved temporarily"

    =?ISO-8859-1?Q?Eino_M=E4kitalo?=, Dec 13, 2004, in forum: Python
    Replies:
    2
    Views:
    820
    =?ISO-8859-1?Q?Eino_M=E4kitalo?=
    Dec 13, 2004
  3. Laszlo Nagy

    urllib2 and HTTP 302

    Laszlo Nagy, May 26, 2006, in forum: Python
    Replies:
    0
    Views:
    349
    Laszlo Nagy
    May 26, 2006
  4. hendy
    Replies:
    0
    Views:
    216
    hendy
    Dec 20, 2005
  5. hendy
    Replies:
    1
    Views:
    255
    Bob Barrows [MVP]
    Dec 20, 2005
Loading...

Share This Page