Pythonanywhere中的Mailgun 404错误

时间:2015-11-17 15:10:18

标签: django mailgun pythonanywhere

我正在尝试在我在Pythonanywhere上托管的Django项目中使用mailgun。

在我的WSGI文件中,我有:

os.environ['DJANGO_MAILGUN_SERVER_NAME'] = 'https://api.mailgun.net/v3/sandboxnumbersomething.mailgun.org/messages'
os.environ['DJANGO_MAILGUN_API_KEY'] ='mykey'

我的设置是:

# EMAIL
# ------------------------------------------------------------------------------
DEFAULT_FROM_EMAIL = env('DJANGO_DEFAULT_FROM_EMAIL',
                         default='Apitrak <noreply@apitrak.com>')
EMAIL_BACKEND = 'django_mailgun.MailgunBackend'
MAILGUN_ACCESS_KEY = env('DJANGO_MAILGUN_API_KEY')
MAILGUN_SERVER_NAME = env('DJANGO_MAILGUN_SERVER_NAME')

当我的应用程序触发电子邮件时(例如在注册时),我遇到404错误:

MailgunAPIError at /accounts/email/

<Response [404]>

Request Method:     POST
Request URL:    https://vincentle.pythonanywhere.com/accounts/email/
Django Version:     1.8.6
Exception Type:     MailgunAPIError
Exception Value:    

<Response [404]>

Exception Location:     /home/vincentle/.virtualenvs/apitrak/lib/python3.4/site-packages/django_mailgun.py in _send, line 154
Python Executable:  /usr/local/bin/uwsgi
Python Version:     3.4.0
Python Path:    

['/var/www',
 '.',
 '',
 '/var/www',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4/lib-dynload',
 '/usr/lib/python3.4',
 '/usr/lib/python3.4/plat-x86_64-linux-gnu',
 '/home/vincentle/.virtualenvs/apitrak/lib/python3.4/site-packages',
 '/home/vincentle/apitrak']

Server time:    Tue, 17 Nov 2015 16:02:28 +0100

我在我的WebApp的virtualenv中尝试过卷曲:

curl -s --user 'api:key-NUMBERS' https://api.mailgun.net/v3/NUMBERS.mailgun.org/messages -F from='Excited User <excited@samples.mailgun.org>' -F to='vincent@vincentle.fr'  -F subject='Hello'  -F text='Testing some Mailgun awesomeness!'

这很好用。

1 个答案:

答案 0 :(得分:3)

设置DJANGO_MAILGUN_SERVER_NAME应该是域名,而不是网址。

尝试以下方法:

os.environ['DJANGO_MAILGUN_SERVER_NAME'] = '<sandboxnumbersomething>.mailgun.org'

来自readme

  

SERVER-NAME替换为“API基本网址”的最后一部分(例如https://api.mailgun.net/v3/<your_server_name>),也可以在您的Mailgun帐户详细信息中找到。