SparkPost / python-sparkpost

SparkPost client library for Python
https://www.sparkpost.com
Other
92 stars 70 forks source link

Unicode display name causes UnicodeEncodeError in sparkpost.transmissions.send() in Python 2.7 #155

Open wodow opened 7 years ago

wodow commented 7 years ago

Using v1.3.5, calling sparkpost_client.transmissions.send(**message)

with message containing ... 'recipients': [ u'REDACTED Hernández <REDACTED@hotmail.com>' ], ...

results in this stacktrace:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 9: ordinal not in range(128)
... 
File "sparkpost/transmissions.py", line 253, in send
    payload = self._translate_keys(**kwargs)
  File "sparkpost/transmissions.py", line 76, in _translate_keys
    bcc_copies = self._format_copies(recipients, bcc)
  File "sparkpost/transmissions.py", line 100, in _format_copies
    'header_to': self._format_header_to(recipients[0])
  File "sparkpost/transmissions.py", line 109, in _format_header_to
    email=recipient['address']['email']

Should it accept a unicode string as a param? It did in an earlier version - tested on v1.2.0 so far.

wodow commented 7 years ago

The exception is raised at https://github.com/SparkPost/python-sparkpost/blame/master/sparkpost/transmissions.py#L105

The inline string there will be a str in Python 2, so can't interpolate a unicode string.