Bug 125013 - Python error 'certificate verify failed (_ssl.c:719)'
Summary: Python error 'certificate verify failed (_ssl.c:719)'
Status: UNCONFIRMED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
6.2.3.1 rc
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-Python
  Show dependency treegraph
 
Reported: 2019-04-28 17:30 UTC by Leif Lodahl
Modified: 2020-11-22 13:18 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Example script to demo error (1.97 KB, text/x-python)
2019-04-28 17:33 UTC, Leif Lodahl
Details
Example that fails in LibreOffice (245 bytes, text/x-python)
2019-10-21 19:14 UTC, Leif Lodahl
Details
This plain Python works (214 bytes, text/x-python)
2019-10-21 19:16 UTC, Leif Lodahl
Details
Generic Python module that works (903 bytes, text/x-python)
2019-12-05 19:57 UTC, Leif Lodahl
Details
LibreOffice function that calls the generic function (397 bytes, text/x-python)
2019-12-05 19:59 UTC, Leif Lodahl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leif Lodahl 2019-04-28 17:30:01 UTC
Description:
Using Urlopen or urlretreive from urllib.request fails 

This could be related to this bug: #109241.

Steps to Reproduce:
1. Get the spreadsheet file from #109241
2. Execute

Actual Results:
Error: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:719)>

Expected Results:
No error


Reproducible: Always


User Profile Reset: No



Additional Info:
This has been a problem on Linux for some time. I think #109241 was classified as Windows only by mistake.
Comment 1 Leif Lodahl 2019-04-28 17:33:36 UTC
Created attachment 151055 [details]
Example script to demo error

The download macro reproduces the error.
Comment 2 Xisco Faulí 2019-05-13 15:15:53 UTC
I don't think this a LibreOffice problem but a request problem.
Please check https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error
Closing as RESOLVED NOTABUG. Put it back to UNCONFIRMED if you disagree
Comment 3 Leif Lodahl 2019-05-13 17:00:28 UTC
Hi Xisco,
Thank you. Your effort is appreciated.
But I disagree :-)

For two reasons:
A very similar problem on Windows was fixed some time ago.
The article on Stackoverflow that you refer to is Python 2.7 and a completely different library (Urllib2).

I will add Michael Stahl as he fixed #109241. 

@Michael: If you agree with Xisco I'll accept the case to be closed.
Comment 4 Michael Stahl (allotropia) 2019-05-14 09:15:11 UTC
bug 109241 is about urllib not supporting https protocol at all, while if you get a CERTIFICATE_VERIFY_FAILED error it clearly does try to use https, so it's a different problem.

the 2 most likely reason why you get a CERTIFICATE_VERIFY_FAILED error is that either the server certificate or one of its signing CA certificates is expired; or the server certificates's CA certificate chain doesn't have a trusted root in the bundled certificates that CPython uses, which i'd assume (but haven't checked) are the bundled certificates of LO's OpenSSL library.

without knowing what the reason of the CERTIFICATE_VERIFY_FAILED error is, it's hard to tell of course...

of course ideally urlib would use the operating system's CA store to verify stuff instead of whatever OpenSSL bundles, which would give the user a UI tool to add additional trusted CA certificates or remove default ones they don't trust - but i have no idea if that is possible.
Comment 5 Leif Lodahl 2019-05-14 18:49:40 UTC
All I can see is that a very simple  urllib.request.urlretreive script works when using the normal Python interpreter but fails when using the built in interpreter that ships with LibreOffice.
Comment 6 Xisco Faulí 2019-10-21 12:04:47 UTC
(In reply to Leif Lodahl from comment #5)
> All I can see is that a very simple  urllib.request.urlretreive script works
> when using the normal Python interpreter but fails when using the built in
> interpreter that ships with LibreOffice.

Hi Leif,
Could you please attach a simple script that works in normal python and fails in LibreOffice ?
Comment 7 Leif Lodahl 2019-10-21 19:14:43 UTC
Created attachment 155211 [details]
Example that fails in LibreOffice

This script file can be placed in ~/.config/libreoffice/4/user/Scripts/python
Run from Writer using Tools - Macros - Run macro -> My macros -> InsertImageTest -> download
Comment 8 Leif Lodahl 2019-10-21 19:16:35 UTC
Created attachment 155212 [details]
This plain Python works

Run with >> python3 InsertImageTestclean.py

Look in the folder.
Comment 9 Leif Lodahl 2019-10-21 19:19:12 UTC
(In reply to Xisco Faulí from comment #6)

Hi Xisco


Thank you very much for your effort.

I have attached two wimple scripts. Both scripts should be changed to download to an existing path on your computer.
If you are not using Linux just replace with a path on your harddrive.
Comment 10 QA Administrators 2019-10-22 02:33:26 UTC Comment hidden (obsolete)
Comment 11 Leif Lodahl 2019-12-05 19:57:05 UTC
Created attachment 156336 [details]
Generic Python module that works

This is a generic Python module that works outside LibreOffice.
Comment 12 Leif Lodahl 2019-12-05 19:59:16 UTC
Created attachment 156337 [details]
LibreOffice function that calls the generic function

Here is the LibreOffice script that calls the generic Python module.
(change the folder to append in line 3)

In LibreOffice urllib fails.
Comment 13 Leif Lodahl 2019-12-05 20:02:31 UTC
I added two scripts to the bug.
Ipsum.py is a Python module that returns a piece of text from the web with urlopen.
TestAnything.py is a Python script for LibreOffice that calls the function in Ipsum.py and inserts the text in a Writer document.

It fails!
Comment 14 Buovjaga 2020-04-28 18:39:38 UTC
(In reply to Leif Lodahl from comment #13)
> I added two scripts to the bug.
> Ipsum.py is a Python module that returns a piece of text from the web with
> urlopen.
> TestAnything.py is a Python script for LibreOffice that calls the function
> in Ipsum.py and inserts the text in a Writer document.
> 
> It fails!

I get

com.sun.star.uno.RuntimeException: Error during invoking function insertIpsum in module file:///home/user/libreoffice/instdir/share/Scripts/python/TestAnything.py (<class 'NameError'>: name 'paras' is not defined
  File "/home/tonttu/libreoffice/instdir/program/pythonscript.py", line 915, in invoke
    ret = self.func( *args )
  File "/home/user/libreoffice/instdir/share/Scripts/python/TestAnything.py", line 12, in insertIpsum
    doc.getText().setString(Ipsum.getLoremipsum(1,paras,yes))
)

Please advise.