Avoiding the error - ValueError: invalid literal for int() with base 10 #201
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Traceback (most recent call last):
File "/opt/mailbox/inbox.py", line 161, in read_imap
for uid, message in unread_inbox_messages:
File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/messages.py", line 55, in _fetch_email_list
yield uid, self._fetch_email(uid)
File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/messages.py", line 44, in _fetch_email
parser_policy=self.parser_policy)
File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 155, in fetch_email_by_uid
email_object = parse_email(raw_email, policy=parser_policy)
File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 212, in parse_email
attachment = parse_attachment(part)
File "/usr/local/lib/python3.6/site-packages/imbox-0.9.8-py3.6.egg/imbox/parser.py", line 122, in parse_attachment
filename_parts.insert(int(s_name[1]),value[1:-1] if value.startswith('"') else value)
ValueError: invalid literal for int() with base 10: ''
I think the problem is because (not sure):
For some pdf attachments the filename field is empty. This is because sometimes the file name is indicated in the content-type field.
This simple change avoid the whole script loop being stuck