element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Community Hub
Community Hub
Member's Forum Rapsberry Pi Build
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Leaderboard
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Community Hub to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 7 replies
  • Subscribers 575 subscribers
  • Views 642 views
  • Users 0 members are here
  • help
  • raspberry pi
  • gmail
Related

Rapsberry Pi Build

don7875
don7875 over 7 years ago

Hi guys I need some help I am following a Guide to feed my cat via email using a raspberry pi here is the link. http://storiknow.com/automatic-cat-feeder-using-raspberry-pi/  seems pretty straight forward but when I get two part two I put in my username and password and get this error below back and im an 100% sure I do not have the wrong username and password. any suggestions?

 

The Error I am Getting:

 

Logging in as <siguykittykat>

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "GmailWrapper.py", line 15, in __init__

    self.login()

  File "GmailWrapper.py", line 20, in login

    server.login(self.userName, self.password)

  File "/usr/local/lib/python2.7/dist-packages/imapclient/imapclient.py", line 284, in login

    raise exceptions.LoginError(str(e))

imapclient.exceptions.LoginError: [AUTHENTICATIONFAILED] Invalid credentials (Failure)

>>>

 

 

My code for the GmailWrapper.py

#!/usr/bin/env python

 

 

from imapclient import IMAPClient, SEEN

 

 

SEEN_FLAG = 'SEEN'

UNSEEN_FLAG = 'UNSEEN'

 

class GmailWrapper:

    def __init__(self, host, userName, password):

        #   force the user to pass along username and password to log in as

        self.host = host

        self.userName = userName

        self.password = password

        self.login()

 

 

    def login(self):

        print('Logging in as ' + self.userName)

        server = IMAPClient(self.host, use_uid=True, ssl=True)

        server.login(self.userName, self.password)

        self.server = server

 

 

    #   An Id in this case identifies a specific email

    def getIdsBySubject(self, subject, unreadOnly=True, folder='INBOX'):

        #   search within the specified folder, e.g. Inbox

        self.setFolder(folder)

 

 

        #   build the search criteria (e.g. unread emails with the given subject)

        self.searchCriteria = [UNSEEN_FLAG, 'SUBJECT', subject]

         if(unreadOnly == False):

            #   force the search to include "read" emails too

            self.searchCriteria.append(SEEN_FLAG)

 

 

        #   conduct the search and return the resulting Ids

        return self.server.search(self.searchCriteria)

 

 

    def markAsRead(self, mailIds, folder='INBOX'):

        self.setFolder(folder)

        self.server.set_flags(mailIds, [SEEN])

 

 

    def setFolder(self, folder):

        self.server.select_folder(folder)

  • Sign in to reply
  • Cancel

Top Replies

  • the48sicks
    the48sicks over 7 years ago +1
    Just having a stab in the dark here, ive not used the wrapper myself. however! ** assuming you are using a google account and the login details are correct ** When using these kinds of things there is…
  • don7875
    don7875 over 7 years ago in reply to the48sicks +1
    Thanks Matt, Man I was so excited I thought that would be it but I am still getting the error. Thanks for taking the time to help me out though, Joe
  • the48sicks
    the48sicks over 7 years ago

    Just having a stab in the dark here, ive not used the wrapper myself. however!

     

    ** assuming you are using a google account and the login details are correct **

     

    When using these kinds of things there is a setting in google to allow  IMAP and "Insecure systems"

     

    In google go to My Account > Sign in and Security then down the bottom change "Allow less secure apps" to   "ON"

     

    You may also need to go into your gmail settings and allow IMAP   Settings > Forwarding and POP/IMAP  "Allow IMAP"

     

     

    HTH

     

     

    Matt

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • don7875
    don7875 over 7 years ago in reply to the48sicks

    Thanks Matt,

     

    Man I was  so excited I thought that would be it but I am still getting the error.

     

    Thanks for taking the time to help me out though,

     

    Joe

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • the48sicks
    the48sicks over 7 years ago in reply to don7875

    Sorry that didnt sort it Jon!

     

    I would just double check that the toggle for less secure apps has saved in the On position (sometimes it doesn't)  and possibly even use a Microsoft outlook client just to double check that your remote access is indeed working. At least then you can rule that out and re-focus on the library

     

     

    I have to go through this process to archive off our staff mail boxes and sometimes the external auth can be a bit funny.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • erlemannoü
    erlemannoü over 7 years ago

    try changing lines:

            self.userName = userName

            self.password = password

     

    to:

            self.userName = str(userName)

            self.password = str(password)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • storiknow
    storiknow over 7 years ago

    Hey Joe:

     

    I'm actually the author of that post and am glad to see you're giving it a go! If you're following the tutorial directly, you'll have setup "two-step authentication" in your Gmail account, and then you'll have generated a password. if you did this, the password will be a 16 character code and will separate every 4 characters with spaces. Here's an example: xxxx xxxx xxxx xxxx.

     

    When you create the password initially it'll pop-up for you, at which point you likely copy/ pasted it. I've found that, once pasted, the spaces will be removed and you'll be left with something like "xxxxxxxxxxxxxxxx". This is no longer a valid password!

     

    Give it another shot, but this time manually type the password in and be sure to include the spaces:

     

    gmailWrapper = new GmailWrapper('imap.gmail.com', 'userName', 'xxxx xxxx xxxx xxxx');

     

    Also, enclose each parameter in single quotes. If you continue having issues, feel free to contact me through the site, I'll be happy to debug with you.

     

    Good luck!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • john-broderick@hotmail.com
    john-broderick@hotmail.com over 7 years ago in reply to storiknow

    Who is Joe ?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • don7875
    don7875 over 7 years ago in reply to storiknow

    Thanks for your help Sam I have it working and will be ordering the motor this weekend!!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube