I have written a project in python which i am now in the process of moving to google app engine. The problem that occurs is when i run this code on GAE
import requests
from google.appengine.api import urlfetch
def retrievePage(url, id):
response = 'http://online2.citybreak.com/Book/Package/Result.aspx?onlineid=%s' % id
# Set the timeout to 60 seconds
urlfetch.set_default_fetch_deadline(60)
# Send the first request
r1 = requests.get(url)
cookies = r1.cookies
print 'Cookies: %s' % r1.Cookies
# Retrieve the content
r2 = requests.get(response, cookies=cookies)
return r2.text
When running the code on GAE the cookies from the first request are missing. That is to say, r1.Cookies is just an empty cookie jar. The same code works just fine on my django server where the cookies should contain a asp.net session id.
The reason i have two requests is because the first one redirects the user and will only retrieve the correct page if the session cookie is the same.
print output on GAE
Cookies: <<class 'requests.cookies.RequestsCookieJar'>[]>
print output on Django
Cookies: <<class 'requests.cookies.RequestsCookieJar'>[<Cookie ASP.NET_SessionId=dhmk1vt3ujgmhhhmbwsclukb for online2.citybreak.com/>]>
Anyone know what the problem might be? Is GAE stripping away the cookie information? I am also opened to any suggestions on another way to retrieve the page, i just found that the requests module was easier than the alternatives i found.
I have written a project in python which I am now in the process of moving to google app engine. The problem that occurs is when I run this code on GAE:
import requests
from google.appengine.api import urlfetch
def retrievePage(url, id):
response = 'http://online2.citybreak.com/Book/Package/Result.aspx?onlineid=%s' % id
# Set the timeout to 60 seconds
urlfetch.set_default_fetch_deadline(60)
# Send the first request
r1 = requests.get(url)
cookies = r1.cookies
print 'Cookies: %s' % r1.cookies
# Retrieve the content
r2 = requests.get(response, cookies=cookies)
return r2.text
When running the code on GAE the cookies from the first request are missing. That is to say, r1.cookies is just an empty cookie jar. The same code works just fine on my django server where the cookies should contain a asp.net session id.
I tried urlfetch it seems to be showing the cookie headers:
import logging
from google.appengine.api import urlfetch
response = urlfetch.fetch(url)
logging.info(response.headers)