【问题标题】:Error says TypeError: can only concatenate str (not "int") to str错误说 TypeError: can only concatenate str (not "int") to str
【发布时间】:2020-11-21 04:54:08
【问题描述】:

我不确定循环出了什么问题,因为它说 [TypeError: can only concatenate str (not "int") to str] 特别是在这一行 -> msg.body = "Hi.. " + roll_id[i] + " is present for the lecture of " + "Prof. " +str(teacher_name.split('.',1)[0]) + ", which is held on " + excel_date + "@" + time + "hrs" 。有什么想法吗?

    for i in range(len(roll_id)):
        cursor.execute("SELECT student_email,parent_email from student_login where binary roll_id=%s",[roll_id[i]])
        email = list(cursor.fetchone())
        print(type(email[1]))
        print(email[0])
        print(email[1])
        msg = Message('Auto Generated',recipients= [email[0],email[1]])
        msg.body = "Hi.. " + roll_id[i] + " is present for the lecture of " + "Prof. " +str(teacher_name.split('.',1)[0]) + ", which is held on " + excel_date + "@" + time + "hrs"
        msg.html = "Hi.. " + roll_id[i] + " is present for the lecture of " + "Prof. " +str(teacher_name.split('.',1)[0])+ ", which is held on " + excel_date + "@" + time + "hrs"
        mail.send(msg)
    return "<h1>mail sent<h1>"

【问题讨论】:

  • 请完成您的问题以便理解。

标签: python string smtp int


【解决方案1】:

请在提问前进行搜索。 How to resolve TypeError: can only concatenate str (not "int") to str

TypeError: can only concatenate str (not "int") to str What does this mean?

简单地说 - 您需要将 roll_id[i] 转换为字符串。 你投了"teacher_name.split('.',1)[0]",但没有投"roll_id[i]"。如果"excel_date""time" 不是字符串,它们也需要被强制转换。

【讨论】:

    猜你喜欢
    • 2022-11-01
    • 2021-08-18
    • 1970-01-01
    • 2019-02-02
    • 2020-02-29
    • 2020-09-18
    • 1970-01-01
    • 2023-02-25
    • 2021-08-31
    相关资源
    最近更新 更多