下面是views.py的代碼
#encoding:utf-8
from django.shortcuts import render
from django.core.mail import send_mail
from django.conf import settings
from django.http import HttpResponse
def send_a(request):
# 發郵件
subject = '天天生鮮歡迎資訊'
message = ''
sender = settings.EMAIL_FROM #"我的郵箱<1234567@qq,com>"
receiver = ["[email protected]",]
send_mail(subject, message, sender, receiver, fail_silently=False)
return HttpResponse("ok")
下面是我的settings配置的郵箱
# 發送郵件配置#授權碼和郵箱沒有公布出來
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
# smpt服務地址
EMAIL_HOST = 'smtp.qq.com'
EMAIL_PORT = 25
# 發送郵件的郵箱
EMAIL_HOST_USER = '983****[email protected]'#授權碼和郵箱沒有公布出來
# 在郵箱中設定的客戶端授權密碼
EMAIL_HOST_PASSWORD = '***********'#授權碼和郵箱沒有公布出來
# 收件人看到的發件人
EMAIL_FROM = '天天生鮮<983****[email protected]>'
下面是出錯資訊
Internal Server Error: /
Traceback (most recent call last):
File "C:\Program Files\Python35\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "C:\Program Files\Python35\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Program Files\Python35\lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "F:\django_project\send_mail_test\myapp\views.py", line 15, in send_a
send_mail(subject, message, sender, receiver, fail_silently=False)
File "C:\Program Files\Python35\lib\site-packages\django\core\mail\__init__.py", line 60, in send_mail
return mail.send()
File "C:\Program Files\Python35\lib\site-packages\django\core\mail\message.py", line 291, in send
return self.get_connection(fail_silently).send_messages([self])
File "C:\Program Files\Python35\lib\site-packages\django\core\mail\backends\smtp.py", line 103, in send_messages
new_conn_created = self.open()
File "C:\Program Files\Python35\lib\site-packages\django\core\mail\backends\smtp.py", line 70, in open
self.connection.login(self.username, self.password)
File "C:\Program Files\Python35\lib\smtplib.py", line 693, in login
self.ehlo_or_helo_if_needed()
File "C:\Program Files\Python35\lib\smtplib.py", line 599, in ehlo_or_helo_if_needed
if not (200 <= self.ehlo()[0] <= 299):
File "C:\Program Files\Python35\lib\smtplib.py", line 439, in ehlo
self.putcmd(self.ehlo_msg, name or self.local_hostname)
File "C:\Program Files\Python35\lib\smtplib.py", line 366, in putcmd
self.send(str)
File "C:\Program Files\Python35\lib\smtplib.py", line 351, in send
s = s.encode(self.command_encoding)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-6: ordinal not in range(128)
有嘗試過使用import sys
reload(sys)
sys.setdefaultencoding('utf-8')
我的python版本是3.5.2的,不適合我的python版本,希望大神幫忙解決一下
uj5u.com熱心網友回復:
對中文串加Header("xxx","utf-8")
uj5u.com熱心網友回復:
問題我讓我們老師找到了,編程代碼沒有任何問題,只是我的計算機名是中文的,然后就影響到python了
uj5u.com熱心網友回復:
臥槽,我也在學習天天生鮮這個,也會這個位置,搞了一天都沒解決,我電腦名字也是中文....臥槽uj5u.com熱心網友回復:
我的筆記本的電腦不是中文名字呀uj5u.com熱心網友回復:
我的電腦名字也不是, 但也不能發送轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/49874.html
上一篇:centos7 手把手從零搭建深度學習環境 (以TensorFlow2.0為例)
下一篇:大佬救命呀
