Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Python3 sending emails with attachments doesn't work #24

Closed
hleumas opened this Issue Jan 8, 2013 · 4 comments

Comments

Projects
None yet
4 participants

hleumas commented Jan 8, 2013

Trying to send an email having an attachment results in following error:

File "/usr/lib/python3.3/email/generator.py", line 211, in _handle_text
    raise TypeError('string payload expected: %s' % type(payload))

I think the problem is in the encode_string method in response.py file. The method returns bytes object in Python3 but the string is expected.

To fix this, just replace

encoded = base64.encodestring(data)

with

encoded = base64.encodestring(data).decode('ascii')

The same fix needs to be done with quopri.encodestring

These changes applies only to python3 version.

Contributor

t2y commented Jan 9, 2013

Python 2.x email.generator expects basestring (means str or unicode), so it can decode with 'ascii' even if in Python 2.x.

  • python2.7/email/generator.py
        if not isinstance(payload, basestring):
            raise TypeError('string payload expected: %s' % type(payload))

I can confirm this bug. I also confirm the fix by t2y is correct.

Please, merge it as soon as possible and release a 0.10.1 version. I had to remove Python 3 support for my application because of this :-(

Let me know if there is something I can do to help here.

Contributor

t2y commented Jan 28, 2013

I also hope to be merged and I can help.

@tseaver tseaver closed this in 4ff7d47 Jan 28, 2013

Owner

tseaver commented Jan 28, 2013

I have pushed the change, but don't have the rights on PyPI to release the package. mmerickel, can you release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment