我编写了一个脚本,用于自动从rss向社交网络发布状态。对于发布我只使用urllib
和urllib2
,如果我从命令行运行我的脚本 - 它是有效的。但是当我将它上传到GAE服务器并转到它的网址时,我有:HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
那么这里的问题是什么?为什么跑步的结果不同?
代码现在是这样的:
def get_page(url, post = None, cookies = None, referer = None):
if post != None:
post = urllib.urlencode(post)
opener = urllib2.build_opener()
request = urllib2.Request(url, post)
if referer != None:
request.add_header('Referer', referer)
request.add_header('User-Agent', 'Chrome/12.0.742.112')
if cookies != None:
request.add_header('Cookie', cookies)
try:
handle = opener.open(request)
except URLError, details:
print 'URL error: ', details
return ''
data = handle.read()
handle.close()
return data