开发者

HTTP error 302 on GAE

开发者 https://www.devze.com 2023-04-05 11:50 出处:网络
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 G

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号