title: UnicodeDecodeError: Django Generate PDF with weasyprint
body: <p>I am making an app with Django. I want to generate pdf when I browse select link. So I used <strong>weasyprint</strong> module for convert my pdf. I import weasyprint module. But When I run that app, I found some error.
  This is <strong>views.py</strong> file</p>
  
  <pre><code>def customersProfile(request, customer_id, sys_type):
      sys_type=sys_type
      area="profile"
      site_credit = site_credit1
      time_now=timezone.now()
      customers=get_object_or_404(CustomerInfo, pk=customer_id)
  
      html_string = render_to_string('shop/profile.html', {'customers': customers, 'todaydate': today_date,'site_name': 'Moon Telecom', 'time_now': time_now, 'site_credit': site_credit, 'area': area})
      html = HTML(string=html_string)
      result = html.write_pdf()
  
  
      response = HttpResponse(content_type='application/pdf;')
      response['Content-Disposition'] = 'inline; filename=list_people.pdf'
      response['Content-Transfer-Encoding'] = 'binary'
      with tempfile.NamedTemporaryFile(delete=True) as output:
          output.write(result)
          output.flush()
          output = open(output.name, 'r')
          response.write(output.read())
  
      return response
  </code></pre>
  
  <p>This is <strong>HTML</strong> file. I wanna create pdf this html file.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body style&gt;
  
      &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-lg-12"&gt;
                  &lt;div class="site_title" style="text-align:center; margin:0 auto"&gt;
                      &lt;h3&gt;মুন টেলিকম&lt;/h3&gt;
                      &lt;h3&gt;
                          &lt;a href="{% url 'shop:index' %}" target="_blank"&gt;{{site_name}}&lt;/a&gt;
                      &lt;/h3&gt;
                      &lt;div class="invoice_info_one" style="width:100%; text-align:center"&gt;
                          &lt;p&gt;সকল প্রকার মোবাইল সেট, সীম কার্ড, মেমোরী কার্ড, MP-3, সোলার চার্জার, সোলার ফ্যান, মোবাইল ফোনের ব্যাটারী, চার্জার, ক্যাচিং,কাভার,হেডফোন, রেবন, ডিসপ্লে এবং ইলেট্রিক মালামাল বিক্রেতা&lt;/p&gt;
                      &lt;/div&gt;
                      &lt;div class="invoice_location"&gt;
                          &lt;p&gt;জাহাঙ্গীর সুপার মার্কেট, ব্রীজ রোড, ফুলহাতা বাজার, মোডেলগঞ্জ।&lt;/p&gt;
                      &lt;/div&gt;
                      &lt;div class="invoice_contact"&gt;
                          &lt;p&gt;01717-051200(সুকান্ত) 01828-163858(দোকান)&lt;/p&gt;
                          &lt;p&gt;&lt;b&gt;Email:&lt;/b&gt; moontelecom2008@gmail.com&lt;/p&gt;
                      &lt;/div&gt;
                      &lt;div class="copy_right"&gt;
                          {% if site_credit %}
                           &lt;p&gt;{{site_credit}}&lt;/p&gt;
                          {% else %}
                              &lt;a href="{% url 'shop:nothing' %}"&gt;#&lt;/a&gt;
                          {% endif %}
                          &lt;p&gt;&lt;/p&gt;
                      &lt;/div&gt;
  
  
                      &lt;hr&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="container"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-lg-12"&gt;
                      &lt;div class="customer_info"&gt;
                          {% if customers.customer_name %}
                          &lt;h2 style="font-size:15px"&gt;Customer Name:
                              &lt;b&gt; {{customers.customer_name}}&lt;/b&gt;
                          &lt;/h2&gt;
                          {% else %} &lt;p&gt; Name: দেওয়া হয়নি&lt;/p&gt; {% endif %}
  
                          &lt;p style="font-size:14px"&gt;Phone Number:
                              {% if customers.customer_mobile_no %}
                               {{customers.customer_mobile_no}}
                              {% else %}
                              No Mobile Number
                              {% endif %}
                          &lt;/p&gt;
                          &lt;p style="font-size:14px"&gt;Purchase Time: {{customers.customer_sell_date}}&lt;/p&gt;
                          &lt;p style="font-size:14px"&gt;invoice id: &lt;b&gt;{{customers.customer_uid}}&lt;/b&gt;&lt;/p&gt;
                          &lt;p&gt;{{customers.product_warrenty}}&lt;/p&gt;
                      &lt;/div&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="table table-bordered"&gt;
  
              &lt;table class="table"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
  
  
                          &lt;th&gt;Product Name&lt;/th&gt;
                          &lt;th&gt;Product ID&lt;/th&gt;
                          &lt;th&gt;Warrenty&lt;/th&gt;
                          &lt;th&gt;QN&lt;/th&gt;
                          &lt;th&gt;Price&lt;/th&gt;
  
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      &lt;tr&gt;
  
  
                          &lt;td&gt;{{customers.customer_product_name}}&lt;/td&gt;
                          &lt;td&gt;{{customers.customer_product_id}}&lt;/td&gt;
  
                          &lt;td&gt;{% if customers.customer_product_warrenty == '' %}
                          &lt;b&gt;No Warrenty&lt;/b&gt;
                          {% else %}
                          &lt;b&gt; {{customers.customer_product_warrenty}}&lt;/b&gt; Month&lt;/td&gt;
                          {% endif %}
                          &lt;td&gt;{{customers.customer_product_quantity}}&lt;/td&gt;
  
                          &lt;td&gt;{{customers.customer_price}} Taka&lt;/td&gt;
  
  
                      &lt;/tr&gt;
  
                  &lt;/tbody&gt;
                  &lt;tr&gt;
                      &lt;td colspan="3"&gt;&lt;/td&gt;
  
                      &lt;td colspan="1"&gt;
                          &lt;b&gt;Total Amount&lt;/b&gt;
                      &lt;/td&gt;
                      &lt;td colspan="1"&gt;
                          &lt;b&gt;{{customers.customer_price}}&lt;/b&gt; Taka&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
               {% if customers.customer_conditions %}
              &lt;div class="warning"&gt;
                  &lt;p style="font-size:8px; width:500px;line-height:15px;"&gt;&lt;i&gt;{{customers.customer_product_name}} {{customers.customer_conditions}}&lt;/i&gt;&lt;/p&gt;
              &lt;/div&gt;
              {% else %} {% endif %}
  
  
  
  
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="footer"&gt;
          &lt;div class="footer_info"&gt;
              &lt;div class="container"&gt;
                  &lt;div class="row"&gt;
                      &lt;div class="col-lg-12"&gt;
                         &lt;div class="footer_info"&gt;
                          &lt;p&gt;Print date: {{time_now}}&lt;/p&gt;
                              &lt;p&gt;
                                  &lt;b&gt;বিঃদ্রঃ ডেলিভারির সময় মাল বুঝিয়া নিবেন। পরে কোন আপত্তী গ্রহনযোগ্য নয়&lt;/b&gt;
                              &lt;/p&gt;
                              &lt;h5&gt;বিক্রিত মাল ফেরত নেওয়া হয় না&lt;/h5&gt;
                         &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
  &lt;/body&gt;
  </code></pre>
  
  <p>When I was browsing that url. I got this error. I was tring to solve this error. But I cant.</p>
  
  <pre><code>UnicodeDecodeError at /shop/1/customerpage/customerprofile/
  'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte
  Request Method: GET
  Request URL:    http://127.0.0.1:8000/shop/1/customerpage/customerprofile/
  Django Version: 1.11.6
  Exception Type: UnicodeDecodeError
  Exception Value:    
  'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte
  </code></pre>
  
  <p>this is full tracebook
  Environment:</p>
  
  <pre><code>Request Method: GET
  Request URL: http://127.0.0.1:8000/shop/1/customerpage/customerprofile/
  
  Django Version: 1.11.6
  Python Version: 3.5.2
  Installed Applications:
  ['shop.apps.ShopConfig',
   'django.contrib.admin',
   'django.contrib.auth',
   'django.contrib.contenttypes',
   'django.contrib.sessions',
   'django.contrib.messages',
   'django.contrib.staticfiles',
   'crispy_forms',
   'wkhtmltopdf']
  Installed Middleware:
  ['django.middleware.security.SecurityMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.middleware.csrf.CsrfViewMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.contrib.messages.middleware.MessageMiddleware',
   'django.middleware.clickjacking.XFrameOptionsMiddleware']
  
  
  
  Traceback:
  
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py" in inner
    41.             response = get_response(request)
  
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
    187.                 response = self.process_exception_by_middleware(e, request)
  
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py" in _get_response
    185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)
  
  File "/home/asad/Desktop/smartshop/django-app/shop/views.py" in customersProfile
    333.         response.write(output.read())
  
  File "/usr/lib/python3.5/codecs.py" in decode
    321.         (result, consumed) = self._buffer_decode(data, self.errors, final)
  
  Exception Type: UnicodeDecodeError at /shop/1/customerpage/customerprofile/
  Exception Value: 'utf-8' codec can't decode byte 0xe2 in position 10: invalid continuation byte
  </code></pre>