This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: smtplib.py: senderrs[each] -> TypeError: unhashable instance
Type: behavior Stage: resolved
Components: email, Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: barry, mattes, r.david.murray
Priority: normal Keywords:

Created on 2014-11-29 08:57 by mattes, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg231854 - (view) Author: (mattes) Date: 2014-11-29 08:57
I get the following error:

File "/usr/local/Cellar/python/2.7.8_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 731, in sendmail
    senderrs[each] = (code, resp)
TypeError: unhashable instance

senderrs[str(each)] = (code, resp) fixes it. Not sure if that is the best fix though.

See also http://stackoverflow.com/questions/27195432/google-app-engine-mail-send-returns-typeerror-unhashable-instance-in-python2
msg231904 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-11-30 20:56
I'm not familiar with app-engine, so I don't understand the code snippet in the stackoverflow issue.  But what is happening here is that whatever it is you've supplied as the 'to' address is not a string, but sendmail expects it to be.

Now, since rcpt converts its argument to a string, you might think it would be reasonable for senderrs to do the same.  But that would not be correct, since then you would not be able to use whatever you passed in to to_addrs as the key to retrieve values from senderrs.  Even if for some reason one did not consider this important, it still couldn't be changed for backward compatibility reasons.  Basically, the fact that rcpt does the equivalent of str(addr) is an implementation detail.

I'm closing this as not a bug; that is, the values in to_addrs are required to be strings, which is how that attribute is documented.
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67154
2014-11-30 20:56:39r.david.murraysetstatus: open -> closed
resolution: not a bug
messages: + msg231904

stage: resolved
2014-11-29 08:57:52mattescreate