我遇到了urlfetch的问题。似乎对于代码中使用的URL,follow_redirects=True
仅在本地工作。
这是我用于测试的代码:
def redirect_test():
url = 'http://0214.by/job.php?busy=ПОСТОЯННАЯ'
response = urlfetch.fetch(url, follow_redirects=True)
if 'location' in response.headers:
ret = 'redirect ignored. location: %s<br>' % response.headers['location']
url = urlparse.urljoin(url, response.headers['location'])
response = urlfetch.fetch(url, follow_redirects=False)
if 'location' in response.headers:
ret += 'redirect followed manually and another redirect response received'
else:
ret += 'redirect followed manually and no more redirects received'
else:
ret = 'redirect followed automatically'
return ret
问题是,当我在本地运行此代码时,我总是收到"Redirect followed automatically"
消息。在Google应用引擎上部署时,始终会显示"Redirect followed manually and no more redirects received"
消息。
网址会返回重定向到https页面。
这让我觉得只有在出于某种原因在本地运行时才会按预期执行重定向。我很感激有关这可能是由什么造成的任何想法。