Home > other >  Using send_mail send mail coding errors UnicodeEncodeError: 'ASCII' codec can 't enco
Using send_mail send mail coding errors UnicodeEncodeError: 'ASCII' codec can 't enco

Time:09-18

below is views. Py code

 # encoding: utf-8 
The from the django. Shortcuts import render
The from the django. Core. Mail the import send_mail
The from the django. Conf import Settings
The from the django. HTTP import HttpResponse
Def send_a (request) :
Email #
Subject='daily fresh welcome message'
Message='
Sender=Settings. EMAIL_FROM # "my email & lt; 1234567 @ qq, com>"

Receiver=/"1234567 @qq.com",
Send_mail (subject, the message sender, receiver, fail_silently=False)
Return an HttpResponse (" ok ")


here is my email Settings configuration
 
# email configurationEMAIL_BACKEND='django. Core. Mail. Backends. SMTP. EmailBackend'
# SMPT service address
EMAIL_HOST='smtp.qq.com'
EMAIL_PORT=25
# email mailbox
EMAIL_HOST_USER='983 * * * * 201 @qq.com # authorization code and email no published
# set in email client authorization password
EMAIL_HOST_PASSWORD='* * * * * * * * * * *' # authorization code and email no published
# the recipient see the sender
EMAIL_FROM='fresh every day & lt; 983 * * * * 201 @qq.com & gt; '
# authorization code and email no published

here is the error message
 Internal Server Error:/
Traceback (the most recent call last) :
File "C: \ Program Files \ Python35 \ lib \ site - packages, django, core, handlers \ exception py", 34, the line in inner
The response=get_response (request)
The File "C: \ Program Files \ Python35 \ lib \ site - packages, django, core, handlers \ base py", line 126, in _get_response
The response=self. Process_exception_by_middleware (e, request)
The File "C: \ Program Files \ Python35 \ lib \ site - packages, django, core, handlers \ base py", line 124, in _get_response
Callback_args response=wrapped_callback (request, * and * * callback_kwargs)
The File "F: \ django_project \ send_mail_test \ myapp \ views. Py", line 15, in send_a
Send_mail (subject, the message sender, receiver, fail_silently=False)
File "C: \ Program Files \ Python35 \ lib \ site - packages \ django/core/mail/set py", 60, the line in send_mail
Return mail. The send ()
The File "C: \ Program Files \ Python35 \ lib \ site - packages \ django/core/mail/message. Py", line 291, in the send
Return the self. Get_connection (fail_silently). Send_messages ([to self])
The File "C: \ Program Files \ Python35 \ lib \ site - packages \ django \ core/mail/backends/SMTP. Py", line 103, in send_messages
New_conn_created=self. The open ()
The File "C: \ Program Files \ Python35 \ lib \ site - packages \ django \ core/mail/backends/SMTP. Py", line 70, in the open
Self. Connection. The login (self. The username, the self. The password)
The File "C: \ Program Files \ Python35 \ lib \ smtplib py", line 693, in the login
Self. Ehlo_or_helo_if_needed ()
The File "C: \ Program Files \ Python35 \ lib \ smtplib py", line 599, in ehlo_or_helo_if_needed
If not (200 & lt;=self. Ehlo () [0] <=299) :
The File "C: \ Program Files \ Python35 \ lib \ smtplib py", line 439, in ehlo
Self. Putcmd (self. Ehlo_msg, name or self. Local_hostname)
The File "C: \ Program Files \ Python35 \ lib \ smtplib py", line 366, in putcmd
The self. The send (STR)
The File "C: \ Program Files \ Python35 \ lib \ smtplib py", line 351, in the send
S=s.e ncode mand_encoding (self.com)
UnicodeEncodeError: 'ASCII' codec can 't encode characters in position 5-6: ordinal not in range (128)


Have tried using the import sys

Reload (sys)
Sys. Setdefaultencoding (' utf-8)

My python version is 3.5.2, not suitable for python version, I hope god help me solve the

CodePudding user response:

For Chinese string plus the Header (" XXX, "" utf-8")

CodePudding user response:

Problems I let our teacher found, programming code without any problem, just my computer name is in Chinese, and then affect the python

CodePudding user response:

Oh my god, I also in learning, fresh every day this will be the location, haven't solved, has set up a day my computer name is in Chinese... Oh my god

CodePudding user response:

My laptop computer is not Chinese name

CodePudding user response:

My computer name is not, but also can't send
  • Related