使用pyramid_mailer会导致ValueError:正在进行TPC

时间:2014-05-26 00:35:18

标签: python pyramid

我在Ubuntu Linux服务器上运行金字塔,在尝试使用ValueError时收到pyramid_mailer。我的代码相对简单,任何事情似乎都会导致它:

def my_view(request):
     mailer = get_mailer(request)
     emailMessage = Message(subject="Welcome", sender="noreply@mysite.com", recipients = ["me@email.com"], body="test")
     mailer.send(emailMessage)

导致此错误:

Traceback (most recent call last):
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/pyramid-1.5-py2.7.egg/pyramid/router.py", line 242, in __call__
    response = self.invoke_subrequest(request, use_tweens=True)
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/pyramid-1.5-py2.7.egg/pyramid/router.py", line 217, in invoke_subrequest
    response = handle_request(request)
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/pyramid_debugtoolbar-2.0.2-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 160, in toolbar_tween
    return handler(request)
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/pyramid-1.5-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween
    response = handler(request)
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/pyramid_tm-0.7-py2.7.egg/pyramid_tm/__init__.py", line 79, in tm_tween
    manager.abort()
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/transaction-1.4.3-py2.7.egg/transaction/_manager.py", line 116, in abort
    return self.get().abort()
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/transaction-1.4.3-py2.7.egg/transaction/_transaction.py", line 468, in abort
    reraise(t, v, tb)
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/transaction-1.4.3-py2.7.egg/transaction/_transaction.py", line 453, in abort
    rm.abort(self)
  File "/usr/share/nginx/wwwProj/local/lib/python2.7/site-packages/repoze.sendmail-4.2-py2.7.egg/repoze/sendmail/delivery.py", line 119, in abort
    raise ValueError("TPC in progress")
ValueError: TPC in progress

我按照"入门(更容易的方式)"的说明进行操作。在此网站上:http://pyramid-mailer.readthedocs.org/en/latest/

3 个答案:

答案 0 :(得分:3)

这是known issue。它可以在此期间通过恢复到repoze.sendmail 4.1(从4.2开始)来解决。

答案 1 :(得分:1)

recipients = ["me@email.com"]

here你可以看到

  • 收件人 - 电子邮件地址列表

答案 2 :(得分:0)

这是我在尝试设置电子邮件系统时遇到的第一个错误,因为我不记得我做了什么。在任何情况下,我终于让它为SMTP的gmail发件人工作。希望我的位置上有其他人:

import smtplib

sender = "noreply"
to = "username"
subject = "Verification Code"

headers = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % (sender, to,
subject)

sEmailMessage = headers + "whatever message you want"

mailserver = smtplib.SMTP("smtp.gmail.com", 587)
#--- because of gmail
mailserver.ehlo()
mailserver.starttls()
mailserver.ehlo()
#---
mailserver.login("your_email_address@gmail.com", "your_password")

mailserver.sendmail("from_here@gmail.com", to_here@whatever.com, sEmailMessage)
mailserver.close()