Error while trying to send test results through email

Asked by Giota Tas

Hello,

Maybe this is not a Sikuli problem but a Python one, so sorry if question is misplaced! Here is my problem :
I have written a script that runs a suite of 4 test cases, creates Test Results with HTML Test Runner and puts results in a file. Fine till here. Then I am using a function found in python takes the file as an attachment and sends it through email :

def sendMail(to, subject, text, files=[],server="localhost"):
    assert type(to)==list
    assert type(files)==list

    fro = "Test Name <email address hidden>"
    msg = MIMEMultipart()
    msg['From'] = fro
    msg['To'] = COMMASPACE.join(to)
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject

    msg.attach( MIMEText(text) )
    for file in files:
        part = MIMEBase('application', "octet-stream")
        part.set_payload( open(file,"rb").read() )
        Encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(file))
        msg.attach(part)
    smtp = smtplib.SMTP(server)
    smtp.sendmail(fro, to, msg.as_string() )
    smtp.close()

sendMail(["<email address hidden>"],"hello","cheers",["C:\Report.html"])

The problem is that when the function runs I get the below error :

 assert type(to)==list
TypeError: type(): 1st arg can't be coerced to String

Why can't it take "<email address hidden>" as a String? Any suggestions?
Thank you!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

yes, this is a weird Sikuli problem:
Sikuli's type() overwrites Python's type() (the error comes from Sikuli's type() ;-)

use isInstanceOf() instead.

Revision history for this message
RaiMan (raimund-hocke) said :
#2

see linked bug

Revision history for this message
Ajit (ajitjadhav896) said :
#3

Can you Please Whole Code for Sending Email with Attachment .
Cuz Same code is not working for me.
Please Help.
Thanks,
AJ.

Can you help with this problem?

Provide an answer of your own, or ask Giota Tas for more information if necessary.

To post a message you must log in.