Mandrill python api application error message

I am writing a web application for handling clients / orders in python with asana integration .

For a registered incoming order, an invoice is created as .pdf. I want to send this file to asana as an email attachment using mandrill, because the asana python API does not yet provide attachments.

Since mandrill wants the contents of the attachment to be a base64 encoded string, I create a binary pdf file using this function:

def binaryFile(self, pathToFile):
    binary_obj = xmlrpclib.Binary( open(pathToFile).read() )
    return binary_obj

Together with the file path, I drop this into mandrill as follows:

'attachments': [{'content': binaryFile,
                 'name': pathOfFile,
                 'type': 'application/pdf'}]

When I try to send it all, I get:

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-   packages/mandrill.py", line 1215, in send
return self.master.call('messages/send', _params)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mandrill.py", line 131, in call
  params = json.dumps(params)
  OverflowError: Overlong 3 byte UTF-8 sequence detected when encoding string

Who can hint at what I am doing wrong?

Thanks.

+4
1

, , base64, . :

import base64

def filetobase64(self, inputfilename):
    return base64.b64encode(open(inputfilename, 'rb').read())

.

!

+7

All Articles