question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Xhtml2PDF, Web pages with Images, ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

See original GitHub issue

I have a script which parses the content of the website and converts it to PDF files. The website was not using https but recently switched to it. After that my script stopped working as expected for pages which contain links to images.

The error goes from this line:

pisaStatus = pisa.CreatePDF(
        sourceHtml,                # the HTML to convert
        dest=resultFile)           # file handle to recieve result

For any page which has link to image I get following error:

File "default_old.py", line 164, in convert_html_to_pdf
  dest=resultFile)           # file handle to recieve result
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/document.py", line 97, in pisaDocument
  encoding, context=context, xml_output=xml_output)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/document.py", line 59, in pisaStory
  pisaParser(src, context, default_css, xhtml, encoding, xml_output)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/parser.py", line 708, in pisaParser
  pisaLoop(document, context)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/parser.py", line 648, in pisaLoop
  pisaLoop(node, context, path, **kw)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/parser.py", line 593, in pisaLoop
  pisaLoop(nnode, context, path, **kw)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/parser.py", line 593, in pisaLoop
  pisaLoop(nnode, context, path, **kw)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/parser.py", line 477, in pisaLoop
  attr = pisaGetAttributes(context, node.tagName, node.attributes)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/parser.py", line 117, in pisaGetAttributes
  nv = c.getFile(nv)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/context.py", line 848, in getFile
  return getFile(name, relative or self.pathDirectory)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/util.py", line 673, in getFile
  file = pisaFileObject(*a, **kw)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/site-packages/xhtml2pdf/util.py", line 581, in __init__
  conn.request("GET", path)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/httplib.py", line 1057, in request
  self._send_request(method, url, body, headers)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/httplib.py", line 1097, in _send_request
  self.endheaders(body)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/httplib.py", line 1053, in endheaders
  self._send_output(message_body)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/httplib.py", line 897, in _send_output
  self.send(msg)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/httplib.py", line 859, in send
  self.connect()
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/httplib.py", line 1278, in connect
  server_hostname=server_hostname)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/ssl.py", line 352, in wrap_socket
  _context=self)
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/ssl.py", line 579, in __init__
  self.do_handshake()
File "/home/alexander/.pyenv/versions/2.7.11/lib/python2.7/ssl.py", line 808, in do_handshake
  self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590)

How can I solve it?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
luiszacommented, Dec 13, 2017

Hi, Basically you need to set httpConfig before call pisa.CreatePDF For example:

from xhtml2pdf.config.httpconfig import httpConfig
httpConfig.save_keys('nosslcheck', True)
pisaStatus = pisa.CreatePDF(
        sourceHtml,               
        dest=resultFile) 

other way is setting as a dict

import ssl
from xhtml2pdf.config.httpconfig import httpConfig
httpConfig['context']=ssl._create_unverified_context()
...

0reactions
luiszacommented, Dec 13, 2017

Great,

It’s helps a lot if you could write some documentation about how make it work (based in this issue answers) so I could include in documentation and merge in master faster.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - Xhtml2PDF, Web pages with Images, ssl.SSLError ...
Xhtml2PDF, Web pages with Images, ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590) ... I have a script which parses the ...
Read more >
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ...
Open a terminal and take a look at: /Applications/Python 3.6/Install Certificates.command. Python 3.6 on MacOS uses an embedded version of OpenSSL, ...
Read more >
How to fix Python SSL CERTIFICATE_VERIFY_FAILED
how to fix Python SSL errors when downloading web pages using the https protocol ... [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:590).
Read more >
Https option — xhtml2pdf 0.2.7 documentation
xhtml2pdf --http_nosslcheck https://domain yourfile.pdf. the --http_nosslcheck is a special argument that help to disable the ssl certificate check.
Read more >
[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed ...
TL;DR. The remote website seems to be the problem, not Python. There is likely no fix for this other than to fix the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found