Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Closed

Python3 sending emails with attachments doesn't work #24

hleumas opened this issue Jan 8, 2013 · 4 comments

Comments

@hleumas
Copy link

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.

@t2y
Copy link
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))

@lorenzogil
Copy link

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.

@t2y
Copy link
Contributor

t2y commented Jan 28, 2013

I also hope to be merged and I can help.

@tseaver
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants