title: PermissionError at /generate-pdf [Errno 13] Permission denied weasyprint
body: <p>hello am using weasyprint to generate a pdf whats wrong with my code here getting access denied.</p>
  <pre class="lang-python prettyprint-override"><code>def generate_pdf(request):
      &quot;&quot;&quot;Generate pdf.&quot;&quot;&quot;
      # Model data
      student = Student.objects.all().order_by('last')
  
      # Rendered
      html_string = render_to_string('pdf-output.html', {'student': student})
      html = HTML(string=html_string)
      result = html.write_pdf()
  
      # Creating http response
      response = HttpResponse(content_type='application/pdf;')
      response['Content-Disposition'] = 'inline; filename=list_os_students.pdf'
      response['Content-Transfer-Encoding'] = 'binary'
      with tempfile.NamedTemporaryFile(delete=True) as output:
          output.write(result)
          output.flush()
          output = open(output.name, 'rb')
          response.write(output.read())
  
      return response
  </code></pre>
  <p>If i change the line <code> output = open(output.name, 'rb')</code> to <code> output = open(output.seek(0), 'rb')</code> the page loads to infinity while in console printing</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>[22/Oct/2020 11:36:54] "GET /dashboard HTTP/1.1" 200 84413
  Not Found: /assets/media/avatars/avatar15.jpg
  [22/Oct/2020 11:36:54] "GET /assets/media/avatars/avatar15.jpg HTTP/1.1" 404 2917
  Not Found: /assets/media/avatars/avatar2.jpg
  [22/Oct/2020 11:36:54] "GET /assets/media/avatars/avatar2.jpg HTTP/1.1" 404 2914
  Not Found: /assets/media/avatars/avatar1.jpg
  Not Found: /assets/media/avatars/avatar13.jpg
  [22/Oct/2020 11:36:54] "GET /assets/media/avatars/avatar1.jpg HTTP/1.1" 404 2914
  Not Found: /assets/media/avatars/avatar11.jpg
  [22/Oct/2020 11:36:54] "GET /assets/media/avatars/avatar13.jpg HTTP/1.1" 404 2917
  [22/Oct/2020 11:36:54] "GET /assets/media/avatars/avatar11.jpg HTTP/1.1" 404 2917</code></pre>
  </div>
  </div>
  </p>
  <p>Traceback</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Traceback (most recent call last):
    File "C:\Users\cipher\Python\Django\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
      response = get_response(request)
    File "C:\Users\cipher\Python\Django\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
      response = wrapped_callback(request, *callback_args, **callback_kwargs)
    File "C:\Users\cipher\Python\Django\sis\dashboard\views.py", line 72, in generate_pdf
      output = open(output.name, 'rb')
  
  Exception Type: PermissionError at /generate-pdf
  Exception Value: [Errno 13] Permission denied: 'C:\\Users\\cipher\\AppData\\Local\\Temp\\tmp996pqacl'</code></pre>
  </div>
  </div>
  </p>