I'm working on a program to log the work i do as well as email the monthly log. The problem i'm having is that every time i try to test out the smtp i get an error

Traceback (most recent call last):
  File "C:/Users/palmer_a/Documents/App/testy.py", line 5, in <module>
    import smtplib
  File "C:\Python34\lib\smtplib.py", line 47, in <module>
    import email.utils
  File "C:\Python34\lib\email\utils.py", line 33, in <module>
    from email._parseaddr import quote
  File "C:\Python34\lib\email\_parseaddr.py", line 16, in <module>
    import time, calendar
  File "C:/Users/palmer_a/Documents/App\calendar.py", line 24, in <module>
    class Calendar(ttk.Frame):
  File "C:/Users/palmer_a/Documents/App\calendar.py", line 27, in Calendar
    datetime = calendar.datetime.datetime
AttributeError: 'module' object has no attribute 'datetime'

This is the code i have for the email script

from tkinter import *
from tkinter import ttk
from datetime import date
import sqlite3
import smtplib

def email_log(self):
        # Specifying the from and to addresses

        self.fromaddr = 'remlaproductions@gmail.com'
        self.toaddrs  = 'draedarockstar@gmail.com'
        self.subject = 'EMP Info'

        # Writing the message (this message will appear in the email)

        self.msg = EmailMessage()
        self.msg['Subject'] = self.subject
        self.msg['From'] = Address(self.fromaddr)
        self.msg['To'] = (Address(self.toaddrs))

        self.msg.set_content(""" {} """.format(search_log.self.tree.get_children()))

        # Gmail Login
        self.username = 'remlaproductions'
        self.password = 'draedarockstar'

        #Sending Email

            self.server = smtplib.SMTP('smtp.gmail.com',25)
            self.server.sendmail(self.fromaddr, self.toaddrs, self.msg)
            messagebox.showinfo(title = "Email Update", message = "Email Sent")
            messagebox.showinfo(title = "Email Update", message = "Error sending email")

The problem is that there is a file calendar.py on the python path which shadows the builtin module calendar. The traceback says


but it should be


The solution is to rename the fileApp/calendar.py or to move it out of the python path or to remove the App folder from the python path.

Edit: if there is a file App/calendar.pyc , it must be removed.

Edited 1 Year Ago by Gribouillis

Thanks wasn't even seeing that. thanks for spotting it. no more errors now, just testing the script now to see if the email goes through

Edited 1 Year Ago by Andrae: grammatical error

This question has already been answered. Start a new discussion instead.