meinsm
Goto Top

Problem mit Python und imaplib2

Hallo,

ich habe ein kleines Problem mit einem meiner Python-Scripte.
Unter Python2 funktioniert das ganze ohne Probleme, jetzt wollte ich Stück für Stück auf Python3 umsteigen und jetzt hab ich ein Problem.
Und zwar frage ich mit Python und imaplib2 Mails ab und zwar mit IDLE.

Jetzt hab ich minimale Anpassungen (NICHT im imap-spezifischen Abschnitt) gemacht, um das ganze unter Python3 laufen zu lassen und
da kommt die Meldung "AttributeError: module 'imaplib2' has no attribute 'IMAP4_SSL'".

Kennt jemand das Problem und weiß, woran dies liegt?

Grüße,
meinsm

Content-Key: 327095

Url: https://administrator.de/contentid/327095

Printed on: April 26, 2024 at 00:04 o'clock

Member: meinsm
meinsm Jan 29, 2017 at 13:07:07 (UTC)
Goto Top
Kann mir keiner helfen?

	while True:
		try:
			# Set the following two lines to your creds and server
			con = imaplib.IMAP4_SSL(server);
			con.login(name,password);
			return con;
		except imaplib.IMAP4_SSL.abort:
			if endless == 1:
			#if retries > 0:
				#retries -= 1
				time.sleep(delay);
			else:
				raise;

Das wär der Teil, wo der Fehler auftritt.
Mitglied: 131381
131381 Jan 29, 2017 at 13:58:21 (UTC)
Goto Top
Moin,
liest sich so als hättest du vergessen die SSL-Bibliothek zu importieren
import ssl
Gruß mik
Member: meinsm
meinsm Jan 29, 2017 updated at 14:41:31 (UTC)
Goto Top
Die SSL-Bibliothek ist importiert.
Auch ein Weglassen ändert an der Fehlermeldung nichts.

Habe jetzt von Github die neues Version installiert, jetzt kommt eine andere Fehlermeldung.

python.exe mail.py
  29:23.05 imap.strato.de reader last 20 log messages:
Traceback (most recent call last):
  File "mail.py", line 175, in <module>  
    con = connect()
  File "mail.py", line 164, in connect  
    con = imaplib2.IMAP4_SSL(server)
  File "C:\Python36\lib\site-packages\imaplib2\imaplib2.py", line 2086, in __init__  
    IMAP4.__init__(self, host, port, debug, debug_file, identifier, timeout, debug_buf_lvl)
  File "C:\Python36\lib\site-packages\imaplib2\imaplib2.py", line 388, in __init__  
    self.welcome = self._request_push(tag='continuation').get_response('IMAP4 protocol error: %s')[1]  
  File "C:\Python36\lib\site-packages\imaplib2\imaplib2.py", line 187, in get_response  
    self.ready.wait(sys.float_info.max)
  File "C:\Python36\lib\threading.py", line 551, in wait  
    signaled = self._cond.wait(timeout)
  File "C:\Python36\lib\threading.py", line 299, in wait  
    gotit = waiter.acquire(True, timeout)
OverflowError: timestamp too large to convert to C _PyTime_t

Was kann dies sein?
Mitglied: 131381
131381 Jan 29, 2017 updated at 15:17:31 (UTC)
Goto Top
OverflowError: timestamp too large to convert to C _PyTime_t
Sieht mir nach Bug aus. Wird wahrscheinlich irgend eine Mail in der Mailbox mit Datum Out of Range sein.

Aber wie immer nur Vermutung wenn du hier nur Fetzen aus dem Kontext gerissen postest anstatt dem großen Ganzen.... face-sad
Member: meinsm
meinsm Jan 29, 2017 at 19:10:39 (UTC)
Goto Top
Habe jetzt mal das ganze abgeändert zum Posten hier.

import imaplib2
import time
import ssl
from threading import *
import email
import re
import sys
import configparser
import io
import time
import os
import socket

config = configparser.ConfigParser();

config.read("config_mail.ini");  

server = config.get("mail", "server");  
port = config.getint('mail', 'port');  
name = config.get('mail', 'name');  
password = config.get('mail', 'password');  
folder = config.get('mail', 'folder');  
subject_check = config.get('mail', 'subject_check');  
subject_contains = config.get('mail', 'subject_contains');  
from_check = config.get('mail', 'from_check');  
from_contains = config.get('mail', 'from_contains');  
mail_save = config.get('mail', 'mail_save');  
mail_file = config.get('mail', 'mail_file');  


def mail_handle(msg, num):
	for part in msg.walk():
		if part.get_content_maintype() == 'multipart':  
			continue
		if part.get('Content-Disposition') is None:  
			continue
	data = part.get_payload(decode=True)

	if (mail_save == 1):
		print("Save Mail")  
		f = open('mail_file', 'w')  
		f.write(data)
		f.close()
	con.store(num, '+FLAGS', '\Seen')  


def mail_check(con):
	typ, data = con.search(None, 'UNSEEN')  
	c = 0
	for num in data.split():
		typ, data = con.fetch(num, '(RFC822)')  
		c +=1
		text = data[1]
		msg = email.message_from_string(text)
		if (subject_check == 1 and from_check == 1):
			if (subject_contains in msg['subject'] and from_contains in msg['from']):  
				mail_handle(msg, num)
	
		elif (subject_check == 1 and from_check != 1):
			if (subject_contains in msg['subject']):  
				mail_handle(msg, num)

		elif (subject_check != 1 and from_check == 1):
			if (from_contains in msg['from']):  
				mail_handle(msg, num)

class Idler(object):
	def __init__(self, conn):
		self.thread = Thread(target=self.idle)
		self.con = conn
		self.event = Event()
 
	def start(self):
		self.thread.start()
 
	def stop(self):
		self.event.set()
 
	def join(self):
		self.thread.join()
 
	def idle(self):
		while True:
			mail_check(con)

			if self.event.isSet():
				return
			self.needsync = False

			def callback(args):
				if not self.event.isSet():
					self.needsync = True
					self.event.set()

			self.con.idle(callback=callback)

			self.event.wait()

			if self.needsync:
				self.event.clear()
				self.dosync()
 
	def dosync(self):
		mail_check(con)		

def connect(delay=30):
	while True:
		try:
			con = imaplib2.IMAP4_SSL(server)
			con.login(name,password)
			return con
		except imaplib2.IMAP4_SSL.abort:
				time.sleep(delay)
			else:
				raise

con = connect()

while True:
	try:
		con.select()
		inbox = con.select()
		idler = Idler(con)
		idler.start()
	except:
		print ('Error')  
		con = connect()
Member: laster
laster Mar 29, 2017 at 20:44:06 (UTC)
Goto Top
hallo,

was ist mit
#import imaplib2  # diese nicht
import imaplib
@see https://pymotw.com/3/imaplib/

vG
LS
Member: meinsm
meinsm Apr 04, 2017 at 20:49:14 (UTC)
Goto Top
imaplib hat soweit ich das richtig verstanden habe keine IDLE-Funktion