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

subject encoding #21

Open
thomasgheberg opened this issue Apr 21, 2020 · 0 comments
Open

subject encoding #21

thomasgheberg opened this issue Apr 21, 2020 · 0 comments

Comments

@thomasgheberg
Copy link

thomasgheberg commented Apr 21, 2020

There is a problem when the subject of an email contains a special character such as "°".
In this case, the subject is

'subject': <email.header.Header object at 0x7f799db1d6d0>

Traceback :

Traceback (most recent call last):
File "src/index_emails.py", line 231, in
IOLoop.instance().run_sync(load_from_file)
File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 576, in run_sync
return future_cell[0].result()
File "/usr/lib/python3/dist-packages/tornado/ioloop.py", line 547, in run
result = func()
File "src/index_emails.py", line 196, in load_from_file
upload_batch(upload_data)
File "src/index_emails.py", line 93, in upload_batch
upload_data_txt += json.dumps(item) + "\n"
File "/usr/lib/python3.8/json/init.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type Header is not JSON serializable

Possible resolution in def convert_msg_to_json:

    if "subject" in result:
        result['subject'] = str(result['subject'])

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

No branches or pull requests

1 participant