742: Email Authentication Error

elguero********@gmai***** (Google Code) (Is this you? Claim this profile.)
Jan. 24, 2009
What's the URL of the page containing the problem?
http://(server ip address)/r/7/publish/

What steps will reproduce the problem?
1. Publish a review request

What is the expected output? What do you see instead?
Return to dashboard.  Instead get the error: TypeError at /r/7/publish/
character mapping must return integer, None or unicode

What operating system are you using? What browser?
Windows XP SP3, Chrome dev

Please provide any additional information below.
The error appears to happen while trying to sending out the email for the 
review request.  Our email server requires authentication and it appears 
that while trying to authenticate the script errors out.  The following is 
the traceback:

Environment:

Request Method: GET
Request URL: http://(server ip address)/r/7/publish/
Django Version: 1.0-final-SVN-unknown
Python Version: 2.6.0
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.markup',
 'django.contrib.sites',
 'django.contrib.sessions',
 'djblets.datagrid',
 'djblets.feedview',
 'djblets.siteconfig',
 'djblets.util',
 'djblets.webapi',
 'reviewboard.accounts',
 'reviewboard.admin',
 'reviewboard.changedescs',
 'reviewboard.diffviewer',
 'reviewboard.iphone',
 'reviewboard.reports',
 'reviewboard.reviews',
 'reviewboard.scmtools',
 'reviewboard.webapi',
 'django_evolution']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'djblets.siteconfig.middleware.SettingsMiddleware',
 'reviewboard.admin.middleware.LoadSettingsMiddleware',
 'djblets.log.middleware.LoggingMiddleware',
 'reviewboard.admin.middleware.CheckUpdatesRequiredMiddleware')


Traceback:
File "/usr/local/lib/python2.6/site-packages/django/core/handlers/base.py" 
in get_response
  86.                 response = callback(request, *callback_args, 
**callback_kwargs)
File "/usr/local/apache2/reviewboard/djblets/auth/util.py" in _checklogin
  45.             return view_func(request, *args, **kwargs)
File "/usr/local/apache2/reviewboard/reviews/views.py" in publish
  448.         review_request.publish(request.user)
File "/usr/local/apache2/reviewboard/reviews/models.py" in publish
  438.                 mail_review_request(user, self, changes)
File "/usr/local/lib/python2.6/site-packages/django/core/mail.py" in send
  265.         return 
self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.6/site-packages/django/core/mail.py" in 
send_messages
  166.         new_conn_created = self.open()
File "/usr/local/lib/python2.6/site-packages/django/core/mail.py" in open
  137.                 self.connection.login(self.username, self.password)
File "/usr/local/lib/python2.6/smtplib.py" in login
  574.             (code, resp) = self.docmd(encode_cram_md5(resp, user, 
password))
File "/usr/local/lib/python2.6/smtplib.py" in encode_cram_md5
  538.             response = user + " " + hmac.HMAC(password, 
challenge).hexdigest()
File "/usr/local/lib/python2.6/hmac.py" in __init__
  72.         self.outer.update(key.translate(trans_5C))

Exception Type: TypeError at /r/7/publish/
Exception Value: character mapping must return integer, None or unicode
chipx86
#1 chipx86
I assume you have a username and password specified in your settings?

What mail server are you using?
  • +NeedInfo
  • +Component-EMail
    +Milestone-Release1.0
#2 elguero********@gmai***** (Google Code) (Is this you? Claim this profile.)
Yes, I tried two different accounts with different usernames and passwords just to 
double check.

The email is hosted by another company but when I telnet in the banner says "(IMail 
9.23 195883-1) NT-ESMTP Server X1".

Thanks
david
#3 david
This looks to me like an internal bug in the hmac library.
chipx86
#4 chipx86
This is a bug with hmac in Python 2.6.
  • -NeedInfo
    +ThirdParty
#5 elguero********@gmai***** (Google Code) (Is this you? Claim this profile.)
I have continued to mess around with this whenever I get a chance.  It seems to me 
that the problem is that the password is being sent to hmac as unicode and it is 
expecting a string.

I created the following patch which seems to be working on my system.  I am very new 
to python and I am not sure if this would be the proper way to take care of this.  
But maybe this will help come up with a solution in order for authenticated smtp to 
work properly.

Thanks
  • +
    Index: reviews/email.py
    ===================================================================
    --- reviews/email.py	(revision 1808)
    +++ reviews/email.py	(working copy)
    @@ -2,6 +2,7 @@
     
     from django.contrib.sites.models import Site
     from django.core.mail import EmailMessage
    +from django.core.mail import SMTPConnection
     from django.template.loader import render_to_string
     
     
    @@ -29,8 +30,8 @@
     
     
     class SpiffyEmailMessage(EmailMessage):
    -    def __init__(self, subject, body, from_email, to, cc, in_reply_to):
    -        EmailMessage.__init__(self, subject, body, from_email, to)
    +    def __init__(self, subject, body, from_email, to, cc, in_reply_to, connection):
    +        EmailMessage.__init__(self, subject, body, from_email, to, None, connection)
     
             self.cc = cc or []
     
    @@ -91,7 +92,7 @@
                 if recipient.is_active:
                     recipients.add(get_email_address_for_user(recipient))
     
    -    siteconfig = current_site.config.get()
    +    siteconfig = current_site.config.get()