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
  is this really a syntax error? Skaperen 4 274 May-25-2024, 07:31 AM
Last Post: snippsat
  World Clock syntax error OscarBoots 1 281 May-03-2024, 05:20 AM
Last Post: snippsat
  Syntax error for "root = Tk()" dlwaddel 15 1,491 Jan-29-2024, 12:07 AM
Last Post: dlwaddel
Photo SYNTAX ERROR Yannko 3 515 Jan-19-2024, 01:20 PM
Last Post: rob101
  String to List question help James_Thomas 6 1,116 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Syntax error while executing the Python code in Linux DivAsh 8 1,863 Jul-19-2023, 06:27 PM
Last Post: Lahearle
  Code is returning the incorrect values. syntax error 007sonic 6 1,373 Jun-19-2023, 03:35 AM
Last Post: 007sonic
  Syntax error? I don't see it KenHorse 4 1,396 Jan-15-2023, 07:49 PM
Last Post: Gribouillis
  Syntax error tibbj001 2 1,002 Dec-05-2022, 06:38 PM
Last Post: deanhystad
  Python-for-Android:p4a: syntax error in main.py while compiling apk jttolleson 2 2,009 Sep-17-2022, 04:09 AM
Last Post: jttolleson

Forum Jump:

User Panel Messages

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