Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6124455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:08:06+00:00 2026-05-23T16:08:06+00:00

I apologise in advance, I know this will be a simple answer but I’m

  • 0

I apologise in advance, I know this will be a simple answer but I’m not having any luck and it’s starting to bug me.

I just want to log into my Gmail account using imaplib and credentials pulled from a file.
I can log into Gmail no worries using:

srv = imaplib.IMAP_SSL("imap.gmail.com")
srv.login("bob@gmail.com", "mypassword")

But instead I’m trying to use a text file (credentials.dat). Inside the file is 2 lines:

bob@gmail.com
mypassword

My code is as follows:

import imaplib
CREDS = open("credentials.dat", "r")

account = CREDS.readline()
password = CREDS.readline()

srv = imaplib.IMAP4_SSL("imap.gmail.com")
srv.login(account, password)

When I run it I get the followign error:

Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    File "/usr/lib64/python2.4/imaplib.py", line 480, in login
       typ, dat = self._simple_command('LOGIN', user, self._quote(password))
    File "/usr/lib64/python2.4/imaplib.py", line 1028, in _simple_command
       return self._command_complete(name, self._command(name, *args))
    File "/usr/lib64/python2.4/imaplib.py", line 865, in _command_complete
       raise self.error('%s command error: %s %s' % (name, typ, data))
       imaplib.error: LOGIN command error: BAD ['Failed to parse your command      r13if7033890ebd.47']

I assume it doesn’t like the data type being entered into srv.login, but I have no idea how else to do it.

There are so many more things I want to do once I get into Gmail (read emails, post, etc), but it’s looking like an uphill battle if I can’t even log in 🙁

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:08:06+00:00Added an answer on May 23, 2026 at 4:08 pm

    readline() includes the newline character at the end of the line, so you’re really saying: login with 'bob@gmail.com\n'

    Try readline().strip() to strip whitespace characters from both sides of the line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings, Apologies in advance that I have not researched this toughly enough to answer
I apologise in advance if this question isn't very specific. Would it be possible
I will apologize in advance as this post is born out of severe frustration.
I apologise in advance if my question seems a bit misleading, but I'm trying
This seems like a simple question to ask but, is it generally a good
I know .ini are not popular in the .net world. I apologize in advance
Apologies in advance for the long-winded question. I'm really a database programmer, but have
I apologize in advance if this question seems remedial. Which would be considered more
Let me apologize in advance for the simplicity of this question (I heard Jeff's
I'm sure this has already been asked and answered so I apologize in advance

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.