Verification of ssl certificates failed after compiling .py to .exe
<p>I have a script that reads to a URL. It works fine if I run it to cmd using <code>python app.py</code>. But after compiling it using py2exe and running the <code>.exe</code> I am getting this error</p>

<pre><code>entering main now.....
Traceback (most recent call last):
  File "strtojson.py", line 257, in &lt;module&gt;
  File "strtojson.py", line 209, in main
  File "requests\api.pyc", line 70, in get
  File "requests\api.pyc", line 56, in request
  File "requests\sessions.pyc", line 475, in request
  File "requests\sessions.pyc", line 596, in send
  File "requests\adapters.pyc", line 497, in send
requests.exceptions.SSLError: [Errno 2] No such file or directory
</code></pre>

<p>Here is  how I access the site. </p>

<pre><code>url = 'https://www.sec.gov/cgi-bin/browse-edgar?company=&amp;CIK=&amp;type=8-k&amp;owner=include&amp;count=100&amp;action=getcurrent'
response = requests.get(url)
html = response.content
soup = BeautifulSoup(html, "html.parser")
</code></pre>

<p>And here is my <code>setup.py</code></p>

<pre><code>from distutils.core import setup
import py2exe
setup(console=['strtojson.py'], options = {'py2exe' : {'packages': ['bs4', 'requests']}})
</code></pre>

<p>Im using Python 2.7.12 on Win 7 64bit</p>

<p>My guess is that Python will not find the trusted CA (needed to validate the server certificates) anymore because they are not included in the exe. In this case using <code>requests.get</code> with <code>verify=False</code> should work. </p>

<p>But this should only be done to verify that this is really the cause of the problem. The better fix would then by to put the necessary trusted CA into a file, ship this file together with the exe and use <code>verify='trusted-ca.pem'</code> then. You can get a widely used collection of trusted CA at <a href="https://curl.haxx.se/docs/caextract.html" rel="nofollow">https://curl.haxx.se/docs/caextract.html</a>.</p>

<p>While it would be nice to make <code>requests</code> use some string as trusted CA I don't think that this is supported. You can of course include the trusted CA as a string inside the exe and then create a temporary file from it before calling <code>requests.get(..., verify='temporary-ca-file.pem')</code>.</p>

python ssl ssl-certificate python-requests