Giter Club home page Giter Club logo

Comments (6)

oernster avatar oernster commented on May 10, 2024

I think this has something to do with the _preparemessage function - line 217 of yagmail.py. There is a dictionary search for headers. I think we need to set headers appropriately. Initially, somewhat naively I set headers in the send function to 'alternative' but it's a dictionary and I have no idea what the key / value pairs should be; though I assume the value is the 'alternative' part.

from yagmail.

oernster avatar oernster commented on May 10, 2024

I noticed on the command line that it was complaining about missing lxml. I pip installed this (I'm using python 3 in virtualenv). However, I now see this error result:

Traceback (most recent call last):
File "etest.py", line 107, in
test_yag()
File "etest.py", line 103, in test_yag
yag.send(to=recipients, headers={'Content-Type':'text/alternative; charset=utf-8'}, subject='title', contents=contents)
File "/home/oliver/Development/item/env3/lib/python3.4/site-packages/yagmail/yagmail.py", line 98, in send
addresses, subject, contents, use_cache, headers)
File "/home/oliver/Development/item/env3/lib/python3.4/site-packages/yagmail/yagmail.py", line 213, in _prepare_message
contents, use_cache)
File "/home/oliver/Development/item/env3/lib/python3.4/site-packages/yagmail/yagmail.py", line 279, in _prepare_contents
content_object = self._get_mime_object(content)
File "/home/oliver/Development/item/env3/lib/python3.4/site-packages/yagmail/yagmail.py", line 362, in _get_mime_object
html_tree = lxml.html.fromstring(content_string)
File "/home/oliver/Development/item/env3/lib/python3.4/site-packages/lxml/html/init.py", line 726, in fromstring
doc = document_fromstring(html, parser=parser, base_url=base_url, *_kw)
File "/home/oliver/Development/item/env3/lib/python3.4/site-packages/lxml/html/init.py", line 614, in document_fromstring
value = etree.fromstring(html, parser, *_kw)
File "lxml.etree.pyx", line 3103, in lxml.etree.fromstring (src/lxml/lxml.etree.c:70569)
File "parser.pxi", line 1828, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:106403)
File "parser.pxi", line 1709, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:105106)
File "parser.pxi", line 1047, in lxml.etree._BaseParser._parseUnicodeDoc (src/lxml/lxml.etree.c:99534)
File "parser.pxi", line 580, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:94350)
File "parser.pxi", line 690, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:95786)
File "parser.pxi", line 631, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:95065)
lxml.etree.XMLSyntaxError: None

I had previously updated the send method to include headers={'Content-Type':'text/alternative;charset=utf-8'}

from yagmail.

oernster avatar oernster commented on May 10, 2024

Note that removing the headers parameter produces the same result. It seems the lxml dependency breaks yagmail in it's current form.

from yagmail.

kootenpv avatar kootenpv commented on May 10, 2024

Thanks for taking the time/effort to report your findings!

I can reproduce the lxml bug when you set the first arguments of the list (instead of the filename in this case) to ''.

It tries to parse '' which fails.

Though, please, contents can be mixed and it would make no sense to add '' to it (though I will take care of it; it could happen legitimately in some templating. If you want to send a message AT THIS MOMENT just don't use '' as an argument).

"First argument" in this case (filename) is nothing special, just omit it.

# works
contents = ['/local/file.png', 'some text',
            '<b><a href="https://github.com/kootenpv/yagmail">a link</a></b>']

# works
contents = ['some text', '<b><a href="https://github.com/kootenpv/yagmail">a link</a></b>']

# doesn't work
contents = ['', 'some text',
                  '<b><a href="https://github.com/kootenpv/yagmail">a link</a></b>']

from yagmail.

oernster avatar oernster commented on May 10, 2024

Thanks for the advice and very swift response to all my issues. The problem is resolved if I remove '' as the first parameter as you described which is great, thanks.

from yagmail.

kootenpv avatar kootenpv commented on May 10, 2024

Great, I'll regard it as closed!

from yagmail.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.