开发者

urlfetch final_url returns None

开发者 https://www.devze.com 2022-12-22 09:32 出处:网络
The product I am working on runs on top of Google Ap开发者_运维技巧p Engine. It contains code similar to this:

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)
0

精彩评论

暂无评论...
验证码 换一张
取 消