You can easily get D by just asking for the current URL.
req = urllib2.Request(starturl, datagen, headers)
res = urllib2.urlopen(req)
finalurl = res.geturl()
To deal with the intermediate redirects you’ll probably need to build your own opener, using HTTPRedirectHandler that records the redirects.