我正在尝试加载一个重定向到自身的 url。我假设它正在加载一个 cookie 并在寻找它,但它从来没有看到它,所以存在这个无限循环的请求。
我试过 urllib2、urlfetch 和 httplib2。没有工作。
我试过这个:
url = "http://www.cafebonappetit.com/menu/your-cafe/collins-cmc/cafes/details/50/collins-bistro"
thing = urllib2.HTTPRedirectHandler()
thing2 = urllib2.HTTPCookieProcessor()
opener = urllib2.build_opener(thing, thing2)
url = 'http://www.nytimes.com/2005/10/26/business/26fed.html?pagewanted=print'
page = opener.open(url)
这适用于 shell,但不适用于 Google App Engine。在 urlfetch 的文档中: http ://code.google.com/appengine/docs/python/urlfetch/fetchfunction.html
在 follow_redirects 下,它说:“重定向时不处理 cookie。如果需要处理 cookie,请将 follow_redirects 设置为 False 并手动处理 cookie 和重定向。”
我不知道如何做到这一点,文档似乎也没有提供任何线索。
我用谷歌搜索了这个问题,没有报告过这样的问题可以解决我的问题。