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
  question about changing the string value of a list element jacksfrustration 4 1,988 Feb-08-2025, 07:43 AM
Last Post: jacksfrustration
  POST Syntax error amplay 0 623 Aug-07-2024, 02:43 PM
Last Post: amplay
  is this really a syntax error? Skaperen 4 1,576 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 1,071 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 6,105 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 1,260 Jan-19-2024, 01:20 PM
Last Post: rob101
  String to List question help James_Thomas 6 2,332 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Syntax error while executing the Python code in Linux DivAsh 8 4,673 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 2,907 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Syntax error? I don't see it KenHorse 4 2,666 Jan-15-2023, 07:49 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

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