0
我有一個簡單的django應用程序,它允許用戶添加一個新用戶。每當我們創建一個新用戶時,一封郵件將發送到相應的email-id(我們在創建新用戶時給的)。如果我添加了任何有電子郵件的新用戶說xxxx @ xxxx.com,郵件將成功發送到[email protected]。這裏沒有問題。在django的testcase中發送電子郵件時出錯?
但是當我嘗試編寫一個用於添加新用戶的測試用例時,我的代碼中的電子郵件發送行中出現錯誤...即TypeError: __init__() takes at most 2 non-keyword arguments (6 given)
。 下面的代碼中給出,
#from my views.py,
Email().send_email(settings.FORGOT_SUBJECT, emailmessage, [username],
settings.CONTENT_TYPE)`
請記住我在這一行,而沒有任何問題,從網頁&郵件發送測試用例期間sucesfully.only收到錯誤在此行中創建的用戶。
# code for SMTP connection
class Email:
def __init__(self):
return;
def send_email(self, subject, message, recipients, contenttype):
"""
Send email using smtp connection.
"""
try:
from django.core.mail import EmailMessage, SMTPConnection, send_mail
from settings import EMAIL_HOST, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_PORT, EMAIL_USE_TLS
finally:
connection = SMTPConnection(EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_USE_TLS)
emailMessage = EmailMessage(subject, message, settings.EMAIL_HOST_USER, recipients)
emailMessage.content_subtype = contenttype
connection.send_messages([emailMessage])
請給出任何解決方案,以避免此錯誤。
TypeError: __init__() takes at most 2 non-keyword arguments (6 given)
在此先感謝。
請發佈回溯,以及您遇到問題的測試代碼 –