当我通过localhost上的mailgun API发送邮件时,它工作正常,但是,当我尝试通过Web应用程序(由Heroku托管,使用Python构建)发送邮件时,似乎出现内部服务器错误。
我的API密钥和URL存储在环境变量中。
在Heroku中,我添加了以下配置变量
MAILGUN_URL
:https://api.mailgun.net/v3/mycustomdomain.io/messages
MAILGUN_API
:我的api密钥。
为什么此API可以与localhost一起使用,但不能在我的应用程序上使用?我的应用程序确实具有SSL证书。
完整日志
2018-09-16T16:49:35.715559+00:00 app[web.1]: {address space usage: 356995072 bytes/340MB} {rss usage: 30208000 bytes/28MB} [pid: 7|app: 0|req: 2/2] 10.182.99.110 () {52 vars in 1007 bytes} [Sun Sep 16 16:49:35 2018] GET /forgotpw => generated 9702 bytes in 14 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
2018-09-16T16:49:38.619559+00:00 heroku[router]: at=info method=POST path="/getnewpassword" host=www.zappay.io request_id=745b2c33-b7df-4334-a634-117d97d5e5ea fwd="115.73.216.193" dyno=web.1 connect=1ms service=105ms status=500 bytes=375 protocol=https
2018-09-16T16:49:38.615016+00:00 app[web.1]: [2018-09-16 16:49:38,609] ERROR in app: Exception on /getnewpassword [POST]
2018-09-16T16:49:38.615032+00:00 app[web.1]: Traceback (most recent call last):
2018-09-16T16:49:38.615034+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 559, in urlopen
2018-09-16T16:49:38.615037+00:00 app[web.1]: body=body, headers=headers)
2018-09-16T16:49:38.615039+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 345, in _make_request
2018-09-16T16:49:38.615040+00:00 app[web.1]: self._validate_conn(conn)
2018-09-16T16:49:38.615042+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 782, in _validate_conn
2018-09-16T16:49:38.615044+00:00 app[web.1]: conn.connect()
2018-09-16T16:49:38.615045+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connection.py", line 250, in connect
2018-09-16T16:49:38.615047+00:00 app[web.1]: ssl_version=resolved_ssl_version)
2018-09-16T16:49:38.615048+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/util/ssl_.py", line 285, in ssl_wrap_socket
2018-09-16T16:49:38.615050+00:00 app[web.1]: return context.wrap_socket(sock, server_hostname=server_hostname)
2018-09-16T16:49:38.615051+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/ssl.py", line 401, in wrap_socket
2018-09-16T16:49:38.615053+00:00 app[web.1]: _context=self, _session=session)
2018-09-16T16:49:38.615055+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/ssl.py", line 808, in __init__
2018-09-16T16:49:38.615056+00:00 app[web.1]: self.do_handshake()
2018-09-16T16:49:38.615058+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/ssl.py", line 1061, in do_handshake
2018-09-16T16:49:38.615059+00:00 app[web.1]: self._sslobj.do_handshake()
2018-09-16T16:49:38.615063+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/ssl.py", line 683, in do_handshake
2018-09-16T16:49:38.615065+00:00 app[web.1]: self._sslobj.do_handshake()
2018-09-16T16:49:38.615067+00:00 app[web.1]: ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
2018-09-16T16:49:38.615069+00:00 app[web.1]:
2018-09-16T16:49:38.615071+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2018-09-16T16:49:38.615072+00:00 app[web.1]:
2018-09-16T16:49:38.615073+00:00 app[web.1]: Traceback (most recent call last):
2018-09-16T16:49:38.615075+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py", line 369, in send
2018-09-16T16:49:38.615076+00:00 app[web.1]: timeout=timeout
2018-09-16T16:49:38.615078+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 588, in urlopen
2018-09-16T16:49:38.615079+00:00 app[web.1]: raise SSLError(e)
2018-09-16T16:49:38.615081+00:00 app[web.1]: requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
2018-09-16T16:49:38.615082+00:00 app[web.1]:
2018-09-16T16:49:38.615084+00:00 app[web.1]: During handling of the above exception, another exception occurred:
2018-09-16T16:49:38.615085+00:00 app[web.1]:
2018-09-16T16:49:38.615087+00:00 app[web.1]: Traceback (most recent call last):
2018-09-16T16:49:38.615101+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1982, in wsgi_app
2018-09-16T16:49:38.615103+00:00 app[web.1]: response = self.full_dispatch_request()
2018-09-16T16:49:38.615105+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1614, in full_dispatch_request
2018-09-16T16:49:38.615106+00:00 app[web.1]: rv = self.handle_user_exception(e)
2018-09-16T16:49:38.615108+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1517, in handle_user_exception
2018-09-16T16:49:38.615110+00:00 app[web.1]: reraise(exc_type, exc_value, tb)
2018-09-16T16:49:38.615111+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/_compat.py", line 33, in reraise
2018-09-16T16:49:38.615113+00:00 app[web.1]: raise value
2018-09-16T16:49:38.615114+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1612, in full_dispatch_request
2018-09-16T16:49:38.615116+00:00 app[web.1]: rv = self.dispatch_request()
2018-09-16T16:49:38.615117+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask/app.py", line 1598, in dispatch_request
2018-09-16T16:49:38.615119+00:00 app[web.1]: return self.view_functions[rule.endpoint](**req.view_args)
2018-09-16T16:49:38.615120+00:00 app[web.1]: File "./src/app.py", line 136, in new_pw
2018-09-16T16:49:38.615122+00:00 app[web.1]: user.send_simple_message()
2018-09-16T16:49:38.615123+00:00 app[web.1]: File "./src/models/user.py", line 131, in send_simple_message
2018-09-16T16:49:38.615125+00:00 app[web.1]: "text": self.verification_code})
2018-09-16T16:49:38.615126+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py", line 109, in post
2018-09-16T16:49:38.615127+00:00 app[web.1]: return request('post', url, data=data, json=json, **kwargs)
2018-09-16T16:49:38.615130+00:00 app[web.1]: response = session.request(method=method, url=url, **kwargs)
2018-09-16T16:49:38.615129+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/api.py", line 50, in request
2018-09-16T16:49:38.615132+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 471, in request
2018-09-16T16:49:38.615133+00:00 app[web.1]: resp = self.send(prep, **send_kwargs)
2018-09-16T16:49:38.615134+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/sessions.py", line 579, in send
2018-09-16T16:49:38.615136+00:00 app[web.1]: r = adapter.send(request, **kwargs)
2018-09-16T16:49:38.615137+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/requests/adapters.py", line 430, in send
2018-09-16T16:49:38.615139+00:00 app[web.1]: raise SSLError(e, request=request)
2018-09-16T16:49:38.615140+00:00 app[web.1]: requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)
2018-09-16T16:49:38.615847+00:00 app[web.1]: {address space usage: 357269504 bytes/340MB} {rss usage: 32284672 bytes/30MB} [pid: 7|app: 0|req: 3/3] 10.182.99.110 () {60 vars in 1164 bytes} [Sun Sep 16 16:49:38 2018] POST /getnewpassword => generated 291 bytes in 102 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)