View Single Post
Old 05-26-2011, 08:24 PM   #77
loureiro
Junior Member
loureiro began at the beginning.
 
Posts: 2
Karma: 10
Join Date: May 2011
Device: Nook
Possible solution to 401 / Optimization

I was getting the 401 error and I think the possible cause is the fact that the "get_browser" function is running for each request and everytime authenticating on Google. Too many authentications = 401. I got the recipe working with the function get_browser "always returning the same browser".

Something like this:


Code:
   

       mybr = None

    def get_browser(self):
	
        br = BasicNewsRecipe.get_browser(self)
        
        if self.mybr is not None:
			return self.mybr
        
        if self.username is not None and self.password is not None:
			
            request = urllib.urlencode([('Email', self.username), ('Passwd', self.password),
                                        ('service', 'reader'), ('accountType', 'HOSTED_OR_GOOGLE'), ('source', __appname__)])
            response = br.open('https://www.google.com/accounts/ClientLogin', request)
            auth = re.search('Auth=(\S*)', response.read()).group(1)
            cookies = mechanize.CookieJar()
            br = mechanize.build_opener(mechanize.HTTPCookieProcessor(cookies))
            br.addheaders = [('Authorization', 'GoogleLogin auth='+auth)]
            self.mybr = br
            
        return br
loureiro is offline   Reply With Quote