使用sendmail()函数时,Django从应用程序收到的响应不完整

时间:2019-03-17 16:50:30

标签: python django django-views smtp

我已经在Django 2.0上构建了一个应用程序,并部署到了pythonanywhere.com。由于Pythonanywhere.com托管没有SMTP服务器,因此我使用了外部服务器(使用hostiq.com SMPT服务器,托管了其他网站)来使用视图发送消息。一切正常,除了价格:)

因此,我将应用程序移至reg.ru托管(因为它便宜且具有SMTP服务器)。除了发送邮件的链接之外,该网络应用程序都可以正常运行。使用发送邮件的所有veiws功能都会失败,并显示错误“从应用程序收到的响应不完整”。您可以通过以下链接自己进行测试:http://www.tajadventures.com/contact-us/

更多可能对解决问题有用的信息:

1)我在共享主机reg.ru中有两个应用程序。 2)我在服务器上使用虚拟环境; 3)客户支持人员说,不允许在共享托管中使用PROXY(例如Working with django : Proxy setup)。 4)这是日志文件所说的(由客户支持发送):

open("/opt/openssl/openssl11/cert.pem", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/opt/openssl/openssl11/certs/6a909d98.0", 0x7ffd3f0aebb0) = -1 ENOENT (No such file or directory)
stat("/opt/openssl/openssl11/certs/4a6481c9.0", 0x7ffd3f0aebb0) = -1 ENOENT (No such file or directory)
stat("/opt/openssl/openssl11/certs/4a6481c9.0", 0x7ffd3f0aebb0) = -1 ENOENT (No such file or directory)

尝试使用端口465连接时,出现以下错误:

ioctl(12, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b0240) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(12, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b01c0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b0870) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b07f0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b0ea0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b0e20) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b14d0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b1450) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b1b00) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b1a80) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b2130) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b20b0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b2760) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b26e0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b2d90) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b2d10) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b33c0) = -1 ENOTTY (Inappropriate ioctl for device)
ioctl(7, SNDCTL_TMR_TIMEBASE or SNDRV_TIMER_IOCTL_NEXT_DEVICE or TCGETS, 0x7ffd3f0b3340) = -1 ENOTTY (Inappropriate ioctl for device)

脚本结束后出现此错误:

write(2, "[ pid=446821, time=2019-03-15 05:51:32,197 ]: WSGI application raised an exception!\nTraceback (most recent call last):\n  File \"/opt/python/python-3.7.0/lib/python3.7/urllib/request.py\", line 1317, in do_open\n    encode_chunked=req.has_header('Transfer-encoding'))\n  File \"/opt/python/python-3.7.0/lib/python3.7/http/client.py\", line 1229, in request\n    self._send_request(method, url, body, headers, encode_chunked)\n  File \"/opt/python/python-3.7.0/lib/python3.7/http/client.py\", line 1275, in _send_request\n    self.endheaders(body, encode_chunked=encode_chunked)\n  File \"/opt/python/python-3.7.0/lib/python3.7/http/client.py\", line 1224, in endheaders\n    self._send_output(message_body, encode_chunked=encode_chunked)\n  File \"/opt/python/python-3.7.0/lib/python3.7/http/client.py\", line 1016, in _send_output\n    self.send(msg)\n  File \"/opt/python/python-3.7.0/lib/python3.7/http/client.py\", line 956, in send\n    self.connect()\n  File \"/opt/python/python-3.7.0/lib/python3.7/http/client.py\", line 1392, in connect\n    server_hostname=server_hostname)\n  File \"/opt/python/python-3.7.0/lib/python3.7/ssl.py\", line 412, in wrap_socket\n    session=session\n  File \"/opt/python/python-3.7.0/lib/python3.7/ssl.py\", line 850, in _create\n    self.do_handshake()\n  File \"/opt/python/python-3.7.0/lib/python3.7/ssl.py\", line 1108, in do_handshake\n    self._sslobj.do_handshake()\nssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1045)\n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n  File \"/var/www/u0673882/data/taj/lib/python3.7/site-packages/django/core/handlers/exception.py\", line 35, in inner\n    response = get_response(request)\n  File \"/var/www/u0673882/data/taj/lib/python3.7/site-packages/django/core/handlers/base.py\", line 128, in _get_response\n    response = self.process_exception_by_middleware(e, request)\n  File \"/var/www/u0673882/data/taj/lib/python3.7/site-packages/django/core/handlers/base"..., 13113) = 13113
write(2, "\n", 1)                       = 1
shutdown(11, SHUT_WR)                   = 0

5)该应用程序可在另一台服务器和本地计算机上正常运行。

6)日志

[Wed Mar 13 19:23:39 2019] [error] [client 217.11.191.130] File does not exist: /var/www/u0673882/data/www/tajadventures.com/b-dropdown.78b8a4cc60332c97c45cdca66a52b299.png, referer: http://www.tajadventures.com/hosting_static_parking.css
[Wed Mar 13 19:25:27 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 19:32:39 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:11:45 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:12:27 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:12:28 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:14:33 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:18:00 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:22:35 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:22:45 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:25:39 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:25:42 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:26:27 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:26:29 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:28:00 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:28:03 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:28:07 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:28:08 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:28:08 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:28:09 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:29:30 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:29:33 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:30:24 2019] [error] [client 217.11.191.130] File does not exist: /var/www/u0673882/data/www/tajadventures.com/b-dropdown.78b8a4cc60332c97c45cdca66a52b299.png, referer: http://www.tajadventures.com/hosting_static_parking.css
[Wed Mar 13 20:30:57 2019] [error] [client 217.11.191.130] File does not exist: /var/www/u0673882/data/www/tajadventures.com/b-dropdown.78b8a4cc60332c97c45cdca66a52b299.png, referer: http://www.tajadventures.com/hosting_static_parking.css
[Wed Mar 13 20:31:20 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
[Wed Mar 13 20:34:40 2019] [error] [client 217.11.191.130] Directory index forbidden by Options directive: /var/www/u0673882/data/www/tajadventures.com/
2019/03/13 23:24:31 [warn] 376904#0: *12310753 upstream server temporarily disabled while reading response header from upstream, client: 54.165.59.7, server: tajadventures.com, request: "GET /blog/1/we-have-released-our-website/ HTTP/1.0", upstream: "http://127.0.0.1:8080/blog/1/we-have-released-our-website/", host: "www.tajadventures.com"
2019/03/13 23:24:35 [warn] 376901#0: *12310776 upstream server temporarily disabled while reading response header from upstream, client: 54.165.59.7, server: tajadventures.com, request: "GET /cars/1/toyota/ HTTP/1.0", upstream: "http://127.0.0.1:8080/cars/1/toyota/", host: "www.tajadventures.com"
2019/03/14 02:31:31 [warn] 90382#0: *12372200 upstream server temporarily disabled while reading response header from upstream, client: 66.249.70.11, server: tajadventures.com, request: "GET /tours/2/dushanbe-city-tour/ HTTP/1.1", upstream: "http://127.0.0.1:8080/tours/2/dushanbe-city-tour/", host: "www.tajadventures.com"
2019/03/14 02:38:43 [warn] 90383#0: *12378817 upstream server temporarily disabled while reading response header from upstream, client: 66.249.70.5, server: tajadventures.com, request: "GET /tours/3/trekking-to-the-lake-sarez/ HTTP/1.1", upstream: "http://127.0.0.1:8080/tours/3/trekking-to-the-lake-sarez/", host: "www.tajadventures.com"
[Thu Mar 14 16:59:31 2019] [error] [client 79.170.191.3] ModSecurity: Warning. Matched phrase "m.js" at RESPONSE_BODY. [file "/etc/httpd/mod_security/trustwave_rules.conf"] [line "2977"] [id "2500005"] [rev "11272018"] [msg "SLR: Bomonero - Crypto-Mining Activity"] [severity "CRITICAL"] [tag "attack-crypto mining"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "https://www.trustwave.com/Resources/Trustwave-Blog/All-the-Ways-Cybercriminals-Are-Exploiting-the-Cryptocurrency-Boom/"] [hostname "www.tajadventures.com"] [uri "/admin/tours/tour/add/"] [unique_id "XIpeQx8fxgQABOQbpd8AAAEQ"]

有什么办法可以解决此错误?谢谢您的宝贵时间。

1 个答案:

答案 0 :(得分:0)

因此,在我看来,该问题的解决方案是从我的视图功能中删除Google的ReCaptcha。我当前的设置如下所示:

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = False
EMAIL_HOST = 'server229.hosting.reg.ru'
EMAIL_PORT = 587
EMAIL_HOST_USER =  'info@domain.com'
EMAIL_HOST_PASSWORD = '********'

但是我认为此错误有很多原因,例如访问不存在的url等。