The product I am working on runs on top of Google Ap开发者_运维技巧p Engine. It contains code similar to this:
result = urlfetch.fetch(url, **parms)
log('%s' %result.final_url)
This always returns None. In the documentation it says it will return the correct URL. But this seems to be a problem. I cannot use the given url since there is a lot of 302 happening in between.
Anybody knows how to solve the same?
Testing on shell.appspot.com demonstrates that final_url is filled in iff a redirect was followed, and is left blank if it wasn't:
>>> from google.appengine.api import urlfetch
>>> urlfetch.fetch('http://google.com/').final_url
'http://www.google.com/'
>>> urlfetch.fetch('http://www.google.com/').final_url
So to get the final URL, just do this:
result = urlfetch.fetch(url, **parms)
final_url = result.final_url or url
log('%s' % final_url)
精彩评论