【问题标题】:urlfetch final_url returns Noneurlfetch final_url 返回无
【发布时间】:2010-03-11 18:54:23
【问题描述】:

我正在开发的产品在 Google App Engine 之上运行。 它包含类似这样的代码:

    result = urlfetch.fetch(url, **parms)
    log('%s' %result.final_url)

这总是返回无。在文档中它说它将返回正确的 URL。但这似乎是个问题。我不能使用给定的 url,因为中间发生了很多 302。

有人知道怎么解决吗?

【问题讨论】:

    标签: google-app-engine urlfetch


    【解决方案1】:

    shell.appspot.com 上的测试表明,如果遵循了重定向,则填写 final_url,如果不是,则将其留空:

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

    所以要获得最终的 URL,只需这样做:

    result = urlfetch.fetch(url, **parms)
    final_url = result.final_url or url
    log('%s' % final_url)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多