Issue225

Title Requests and SSL certificate errors
Priority bug Status deferred
Superseder Nosy List grippa, kayhayen
Assigned To kayhayen Keywords standalone

Created on 2015-08-03.18:20:21 by grippa, last changed by hamilyon.

Messages
msg1691 (view) Author: hamilyon Date: 2015-11-13.09:09:51
This is also a problem for simple tornado http client when using ssl. It relies 
on certifi for cacert.pem file.
msg1407 (view) Author: kayhayen Date: 2015-08-11.06:31:37
It may be easier to use os.environ['REQUESTS_CA_BUNDLE'] and put the filename 
into it, which should be derivable from __file__ dirname joined with the pem 
filename.

So that is sufficient to make a plugin out of that later. It will find the 
request import, and then copy the certificate from the system to Nuitka, while 
also setting the environment variable up. Then it will work without changing 
your source.

But since I am busy with release work, this is deferred.

Yours,
Kay
msg1406 (view) Author: grippa Date: 2015-08-10.20:25:11
So to fix this, you can do:

add cacert.pem (from the requests module folder) to the same folder as the  
compiled exe
then add to your code: cert ='cacert.pem' and to every request the parameter 
verify=cert
msg1398 (view) Author: kayhayen Date: 2015-08-04.07:29:38
Ah, I found this, check it out:

http://stackoverflow.com/questions/17158529/fixing-ssl-certificate-error-in-exe-
compiled-with-py2exe-or-pyinstaller

Just beware that Nuitka has no frozen attribute (yet). The solution to this 
issue, should be to include the certificates from a Nuitka plugin later on.

Yours,
Kay
msg1397 (view) Author: kayhayen Date: 2015-08-04.07:25:53
Hello the warnings are by themselves not an issues generally.

The code that raises the exception looks like this (on my machine):

        try:
            context.load_verify_locations(ca_certs)
        except IOError as e:  # Platform-specific: Python 2.6, 2.7, 3.2
            raise SSLError(e)
        # Py33 raises FileNotFoundError which subclasses OSError
        # These are not equivalent unless we check the errno attribute
        except OSError as e:  # Platform-specific: Python 3.3 and beyond
            if e.errno == errno.ENOENT:
                raise SSLError(e)
            raise

Which then becomes "SSLError" correctly, which exits your program. So I meant to 
see, where this code goes into, but it's not obvious. From my experimentation, 
this include the "_ssl.so". It seems to not have the certificates it wants to 
use, are you using your own ones?

Can you strace the program, when run under CPython, and check for file accesses 
to /etc or /etc/ca-certificates?

Does this happen when you change the machine only? Or on the original machine?

Yours,
Kay
msg1395 (view) Author: grippa Date: 2015-08-03.18:20:20
I have been trying to compile a  script with a dependency on the popular 
libraries, requests and beautifulsoup. These are warnings nuitka outputs 
during the compilation:

C:\Users\user\Desktop>nuitka --recurse-all --standalone args.py
Nuitka:WARNING:C:\Python34\Lib\site-packages\bs4\dammit.py:22: Cannot find 
'ccha
rdet' in package 'bs4' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\bs4\dammit.py:30: Cannot find 
'char
det' in package 'bs4' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\bs4\dammit.py:42: Cannot find 
'icon
v_codec' in package 'bs4' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\bs4\builder\_lxml.py:9: Cannot 
find
 'lxml' in package 'bs4.builder' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\bs4\builder\_html5lib.py:17: 
Cannot
 find 'html5lib' in package 'bs4.builder' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\bs4\builder\_html5lib.py:18: 
Cannot
 find 'html5lib.constants' in package 'bs4.builder' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\packages\
ssl_match_hostname\__init__.py:7: Cannot find 'backports.ssl_match_hostname' 
in
package 'requests.packages.urllib3.packages.ssl_match_hostname' as absolute 
impo
rt.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\packages\
ordered_dict.py:11: Cannot find '_abcoll' in package 
'requests.packages.urllib3.
packages' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\poolmanag
er.py:6: Cannot find 'urlparse' in package 'requests.packages.urllib3' as 
absolu
te import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\requests\compat.py:37: Cannot 
find
'urlparse' in package 'requests' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\requests\compat.py:38: Cannot 
find
'urllib2' in package 'requests' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\requests\compat.py:39: Cannot 
find
'cookielib' in package 'requests' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\requests\compat.py:40: Cannot 
find
'Cookie' in package 'requests' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-packages\requests\certs.py:17: Cannot 
find '
certifi' in package 'requests' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\contrib\p
yopenssl.py:48: Cannot find 'ndg.httpsclient.ssl_peer_verification' in 
package '
requests.packages.urllib3.contrib' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\contrib\p
yopenssl.py:49: Cannot find 'ndg.httpsclient.subj_alt_name' in package 
'requests
.packages.urllib3.contrib' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\contrib\p
yopenssl.py:53: Cannot find 'OpenSSL.SSL' in package 
'requests.packages.urllib3.
contrib' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\contrib\p
yopenssl.py:54: Cannot find 'pyasn1.codec.der' in package 
'requests.packages.url
lib3.contrib' as absolute import.
Nuitka:WARNING:C:\Python34\Lib\site-
packages\requests\packages\urllib3\contrib\p
yopenssl.py:55: Cannot find 'pyasn1.type' in package 
'requests.packages.urllib3.
contrib' as absolute import.
Nuitka:WARNING:Unresolved '__import__' call at 'C:\Python34\Lib\site-
packages\re
quests\packages\urllib3\packages\six.py:74' may require use of '--recurse-
direct
ory'.

And then during execution:

Traceback (most recent call last):
  File 
"C:\Users\user\Desktop\args.dist\requests\packages\urllib3\util\ssl_.py",
 line 267, in ssl_wrap_socket
FileNotFoundError: [Errno 2] No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\args.dist\requests\adapters.py", line 370, in 
send

  File 
"C:\Users\user\Desktop\args.dist\requests\packages\urllib3\connectionpool
.py", line 544, in urlopen
  File 
"C:\Users\user\Desktop\args.dist\requests\packages\urllib3\connectionpool
.py", line 341, in _make_request
  File 
"C:\Users\user\Desktop\args.dist\requests\packages\urllib3\connectionpool
.py", line 761, in _validate_conn
  File 
"C:\Users\user\Desktop\args.dist\requests\packages\urllib3\connection.py"
, line 238, in connect
  File 
"C:\Users\user\Desktop\args.dist\requests\packages\urllib3\util\ssl_.py",
 line 269, in ssl_wrap_socket
requests.packages.urllib3.exceptions.SSLError: [Errno 2] No such file or 
directo
ry

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\Desktop\args.dist\args.py", line 210, in <module>
  File "C:\Users\user\Desktop\args.dist\args.py", line 12, in main
  File "C:\Users\user\Desktop\args.dist\args.py", line 46, in login
  File "C:\Users\user\Desktop\args.dist\requests\sessions.py", line 477, in 
get
  File "C:\Users\user\Desktop\args.dist\requests\sessions.py", line 465, in 
requ
est
  File "C:\Users\user\Desktop\args.dist\requests\sessions.py", line 573, in 
send

  File "C:\Users\user\Desktop\args.dist\requests\adapters.py", line 431, in 
send

requests.exceptions.SSLError: [Errno 2] No such file or directory
History
Date User Action Args
2015-11-13 09:09:51hamilyonsetmessages: + msg1691
2015-08-11 06:31:37kayhayensetstatus: chatting -> deferred
messages: + msg1407
2015-08-10 20:25:11grippasetmessages: + msg1406
2015-08-10 20:24:53grippasetmessages: - msg1405
2015-08-10 20:24:49grippasetmessages: - msg1399
2015-08-10 17:43:57grippasetmessages: + msg1405
2015-08-04 18:47:44grippasetmessages: + msg1399
2015-08-04 07:29:38kayhayensetmessages: + msg1398
title: Requests and beautifulsoup import errors -> Requests and SSL certificate errors
2015-08-04 07:26:12kayhayensetassignedto: kayhayen
keyword: + standalone
nosy: + kayhayen
2015-08-04 07:25:54kayhayensetstatus: unread -> chatting
messages: + msg1397
2015-08-03 18:20:21grippacreate