Python Forum
syntax error question - string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
syntax error question - string
#1
Hi
When I try to include strings(Htitle1) inside some HTML that I want to send in an email, I get this error: TypeError: set_text_content() got multiple values for argument subtype.

The HTML is something I want to include in an email, for example:
email.set_content('<h2 "style ="font-weight:normal;font-size:14px">',Htitle1,'</h2>',subtype='html')
How do I fix this?
thanks
Reply
#2
My assumption is that you cannot break your message up into multiple parts. You are doing this:
email.set_content(
    '<h2 "style ="font-weight:normal;font-size:14px">',
    Htitle1,
    '</h2>',
    subtype='html')
I think subtype is first assigned '</h2>' as a positional argument, then you have a named argument. I think you need to make the message body one string, not three strings. This example uses f'string formatting to insert Htitle1 into the html string. Wouldn't be surprised if there are better tools for this.
Htitle1 = 'whatever'
email.set_content(
    f"""<h2 "style ="font-weight:normal;font-size:14px">{Htitle1}</h2>""",
    subtype='html')
Reply
#3
(Feb-03-2023, 12:02 AM)mgallotti Wrote: email.set_content('<h2 "style ="font-weight:normal;font-size:14px">',Htitle1,'</h2>',subtype='html')

Did you mean to include that double quote before the word style?
Reply
#4
I didn't notice that. A twofer, a Python error and an HTML error.
Reply
#5
Thank you. I will try what you suggested.


(Feb-03-2023, 03:17 AM)deanhystad Wrote: My assumption is that you cannot break your message up into multiple parts. You are doing this:
email.set_content(
    '<h2 "style ="font-weight:normal;font-size:14px">',
    Htitle1,
    '</h2>',
    subtype='html')
I think subtype is first assigned '</h2>' as a positional argument, then you have a named argument. I think you need to make the message body one string, not three strings. This example uses f'string formatting to insert Htitle1 into the html string. Wouldn't be surprised if there are better tools for this.
Htitle1 = 'whatever'
email.set_content(
    f"""<h2 "style ="font-weight:normal;font-size:14px">{Htitle1}</h2>""",
    subtype='html')
Reply
#6
Yes, I did. Thanks
(Feb-03-2023, 01:23 PM)Calab Wrote:
(Feb-03-2023, 12:02 AM)mgallotti Wrote: email.set_content('<h2 "style ="font-weight:normal;font-size:14px">',Htitle1,'</h2>',subtype='html')

Did you mean to include that double quote before the word style?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Syntax error for "root = Tk()" dlwaddel 15 1,155 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 371 Jan-19-2024, 01:20 PM
Last Post: rob101
  String to List question help James_Thomas 6 975 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Syntax error while executing the Python code in Linux DivAsh 8 1,542 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,205 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Syntax error? I don't see it KenHorse 4 1,241 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 881 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 1,828 Sep-17-2022, 04:09 AM
Last Post: jttolleson
  Mysql Syntax error in pymysql ilknurg 4 2,344 May-18-2022, 06:50 AM
Last Post: ibreeden
  Solving equation equal to zero: How to resolve the syntax error? alexfrol86 3 1,950 Feb-21-2022, 08:58 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020