Python---Supplemental Django Chinese error (2), Django3.5 error

Source: Internet
Author: User
Tags iterable

Today is to Django3.5 set up the project, the results appear in Chinese error, although previously analyzed py2.7 error reasons, but after py3 reload not used, need to introduce:

 from importlib import  reload

But this is not any use, because the default encoding after PY3 is no longer bytecode, but utf-8, you can use code to view

Sys.getdefaultencoding ()

And then there's a new error, the place of error.

' bytes ' Object ' encode

Originally holding not to modify the source of attitude, find other solutions, but found a half-day, the results did not find ... And this is not because of the Chinese problem, this has just said, has been the default Utf-8 encoded,

So forget, directly modify the source to see how

def finish_response (self):"""Send any iterable data, then close self and the iterableSubclasses intended forUseinchasynchronous servers'll want to redefine Thismethod, such that it sets up callbacksinchTheEventLoop to iterate through the data, and to call'self.close ()'Once the response isfinished. """        Try:            ifNot self.result_is_file () or not Self.sendfile (): forDatainchself.result: # Data=Data.encode () self.write (data) self.finish_content ()finally: Self.close ()

It turned out to be a success.

Then debug it and see why.

                 for inch Self.result:                    Print (Data,type (data))  #发现这个数据原本类型就是字节型, we do not need to encode again. And the byte type does not have this attribute, this is the cause                    of the error = data.encode ()                    self.write (data)                self.finish_content ()        

Python---Supplemental Django Chinese error (2), Django3.5 error

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.