Hello,

I had the same problem. As I understand, in production urllib2 is
emulated on GAE through urlfetch and the cookie-related features don't
work. As a workaround you can set "Cookie" header explicitly. Here's
some code I used:

import Cookie
#get the cookie from the response:
cookie = Cookie.SimpleCookie(result.headers.get('set-cookie', ''))

#a routine to construct cookie header for requests:
def make_cookie_header(cookie):
    ret = ""
    for val in cookie.values():
        ret+="%s=%s; "%(val.key, val.value)
    return ret

# using the cookie in subsequent requests:
result = urlfetch.fetch(url=url,
                                headers={'Cookie' : make_cookie_header(cookie)})


Hope this helps.

Best Regards,
Alex


On Sun, Aug 9, 2009 at 9:09 AM, aig<[email protected]> wrote:
>
> Prompt please, I wish to make automatic mail check through GAE,
> however the given script works on my computer but does not work in GAE
> enviroment (unable to login):
>
> #!/usr/bin/env python
>
> import cookielib
> import urllib
> import urllib2
>
> cj = cookielib.CookieJar()
> opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
> urllib2.install_opener(opener)
>
> user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
> headers = { 'User-Agent' : user_agent }
> values = {'Email' : '[email protected]',
>          'Passwd' : 'password',
>          'PersistentCookie' : 'yes',
>          'null': 'Sign in',
>          'rm': 'false',
>          'hl': 'en',
>          'service': 'mail',
>          'continue': 'https://mail.google.com/mail/h/'}
>
> data = urllib.urlencode(values)
>
> url = 'https://www.google.com/accounts/ServiceLoginAuth'
> req = urllib2.Request(url, data, headers)
>
> handle = urllib2.urlopen(req)
>
> req = urllib2.Request('https://mail.google.com/mail/h/')
> handle = urllib2.urlopen(req)
>
> print 'Content-Type: text/plain'
> print ''
>
> print handle.read()
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to