urllib2 and HTTP 302

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laszlo Nagy

    #1

    urllib2 and HTTP 302


    Hello,


    The code below uses urllib2 and build_opener. Having this code fragment,
    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_multi part(
    url,
    [('uploadType',' Inventory')],
    [('uploadFileNam e','inv.txt',fd ata)]
    )
    except urllib2.HTTPErr or, e:
    if e.code == 302:
    return "I would like to get the URL to be redirected
    to...."
    else:
    raise

    Thanks,

    Laszlo
Working...