How to auto log into gmail atom feed with Python?

后端 未结 1 1045
感动是毒
感动是毒 2020-12-14 12:12

Gmail has this sweet thing going on to get an atom feed:

def gmail_url(user, pwd):
    return \"https://\"+str(user)+\":\"+str(pwd)+\"@gmail.google.com/gmail         


        
相关标签:
1条回答
  • 2020-12-14 12:22

    You can use the HTTPBasicAuthHandler, I tried the following and it worked:

    import urllib2
    
    def get_unread_msgs(user, passwd):
        auth_handler = urllib2.HTTPBasicAuthHandler()
        auth_handler.add_password(
            realm='New mail feed',
            uri='https://mail.google.com',
            user='%s@gmail.com' % user,
            passwd=passwd
        )
        opener = urllib2.build_opener(auth_handler)
        urllib2.install_opener(opener)
        feed = urllib2.urlopen('https://mail.google.com/mail/feed/atom')
        return feed.read()
    
    0 讨论(0)
提交回复
热议问题