Python Mailgun 问题 - 500 内部服务器错误

问题描述 投票:0回答:1

我刚刚学习 Python 和 VS code,正在接受培训。

根据 Mailgun 文档,我使用 Python 创建了一个 sendmail 脚本 (app.py):

def send_simple_message():
return requests.post(
    "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
    auth=("api", "YOUR_API_KEY"),
    data={"from": "Excited User <mailgun@YOUR_DOMAIN_NAME>",
          "to": ["[email protected]", "YOU@YOUR_DOMAIN_NAME"],
          "subject": "Hello",
          "text": "Testing some Mailgun awesomness!"})

我从终端在 Visual Studio Code 中运行 Python 脚本,如下所示:

 Python app.py

当我使用 Postman 进行测试时,电子邮件发送成功,但在 Postman 中,我收到 500 错误,并且不确定原因:

<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request.     
Either the server is overloaded or there is an error in the application.</p>

仍在尝试了解使用 VS Code 的要点,但这似乎是一个学习曲线。

提前致谢

python api visual-studio-code mailgun
1个回答
0
投票

我使用的 MailGun 文档/Python 示例似乎没有按预期工作:

def send_simple_message():
return requests.post(
    "https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages",
    auth=("api", "YOUR_API_KEY"),
    data={"from": "Excited User <mailgun@YOUR_DOMAIN_NAME>",
          "to": ["[email protected]", "YOU@YOUR_DOMAIN_NAME"],
          "subject": "Hello",
          "text": "Testing some Mailgun awesomness!"})

当我将代码更改为以下内容时:

@app.route('/notifications', methods=['POST'])
def notifications():
 r=requests.post(
    "https://api.mailgun.net/v3/blahblahblah.mailgun.org/messages",
    auth=("api", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
    data={"from": "Mailgun Test <[email protected]>",
          "to": ["addressee", "[email protected]"],
          "subject": "Hello",
          "text": "Testing some Mailgun awesomness!"})
 
 return r.text

我收到以下退货:

© www.soinside.com 2019 - 2024. All rights reserved.