python - How to parse credential args to a function handling imaplib protocols
问题描述
I have a list of emails(mine) that I want to test against a list of passwords(All valid and some none valid of course) using imaplib
library. Whenever I test the program ordinarily like in the code below, it works perfectly no errors.
import sys
import imaplib
# connect to host using SSL
imap_host = 'imap.server.com'
imap_port = '993'
imap_user = 'username@email'
imap_pass = 'RightPassword'
imap = imaplib.IMAP4_SSL(imap_host, imap_port)
## login to server
try:
login = imap.login(imap_user, imap_pass)
if login:
print login
except imaplib.IMAP4.error as error:
print error
#
But whenever I run the code such as to parsing credentials through a function to handle the authentication protocols such as the following code below, I get an error saying
"LOGIN command error: BAD ['Missing \'"\'']".
I have tried all sort of things I could find using google and non seem to handle it properly.
"""
E-mail Tester
NB: This is for educational purpose only.
"""
import sys
import imaplib
EMAILS_FILE = open('email_list.txt', 'r')
PASSWORD_FILE = open('pass_list.txt', 'r')
SUCCESS_FILE = open('success.txt', 'a')
EMAILS_FILE_LIST = []
def set_check(_emails):
email = str(_emails)
PASSWORD_FILE.seek(0)
for passwords in PASSWORD_FILE:
password = str(passwords)
# connect to host using SSL
imap_host = 'imap.server.com'
imap_port = '993'
imap = imaplib.IMAP4_SSL(imap_host, imap_port)
## login to server
try:
# print "%s%s" % (email,password)
# print "I got here so far"
# sys.exit()
print "Testing <--> E-mail: %s - Password: %s" % (email, password)
login = imap.login("%s","%s" % (email, password))
if login:
print login
print "OK <---> E-mail: %s\nPassword: %s" % (email, password)
except imaplib.IMAP4.error as error:
print error
for emails in EMAILS_FILE:
EMAILS_FILE_LIST.append(emails)
for email_count in range(0, len(EMAILS_FILE_LIST)):
set_check(EMAILS_FILE_LIST[email_count])
I have tried all kind of suggestions I could find on the internet but non has worked thus far.
I expect imap.login
to handle the authentication without the mysterious error output
"LOGIN command error: BAD ['Missing \'"\'']"
解决方案
login = imap.login("%s","%s" % (email, password))
不起作用。它在 Python: 中引发错误TypeError: not all arguments converted during string formatting
,因为您向一个 %s 提供了两个字符串。
你为什么不直接使用imap.login(email, password)
?它与您尝试执行的操作具有相同的效果。
你的密码文件是什么样的?它实际上发送的是什么?请在崩溃之前提供日志行。(如有必要,匿名,但留下任何标点符号以帮助诊断)
推荐阅读
- reactjs - React Native 中的流式音频记录
- cascade - TypeORM 级联选项:cascade、onDelete、onUpdate
- java - 如何在 SpringBoot 运行时更改属性值而不重新启动/重新部署应用程序
- javascript - 使用javascript swagger客户端上传文件时遇到问题并做出反应
- .net - UWP WebView 第三方替代品
- wpf - 不能将字符串隐式转换为视图模型
- ios - iOS 共享扩展 - loadItemForTypeIdentifier 调用返回 iOS11 中的文件 url 和 iOS12 中的文件内容
- reactor-netty - TcpClient - 如何发送消息和接收响应?
- javascript - 带有 React 的 Three.js 的 TextGeometry 不起作用
- vue.js - VueJs 路由器设置配置以支持不带斜线的哈希