HTTP error 302 on GAE
I write a script for automatically posting status to social network from rss. For posting I use just urllib
and urllib2
and if I run my script from command line - it's work. But when I upload it to GAE server and go to it's url I have: HTTP Error 302: The HTTP server returned a redirect error that would lead to an infinite loop.
So what's the problem here? Why the result of running is different?
Code is now something like this:
def get_page(url, post = None, cookies = None, referer = None):
if post != None:
post = urllib.urlencode(post)
o开发者_如何学编程pener = 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
精彩评论