Search code examples
python-requestspy2app

mac: py2app not finding cacert.pem


My app created with py2app is not able to find cacert.pem. The error stack shown below says it's looking into the zip file in the app bundle. I checked the zip file and the cacert.pem seems to be in the right place.

I have tried the solution suggested here to copy cacert.pem to the requests package so it can be found during p2app compile, with no success.

I am using Anaconda with python 3.5 on Mac.

Any ideas?

  File "/Users/chuck/Documents/patelco/monitor/dist/monitor.app/Contents/Resources/__boot__.py", line 98, in <module>
    _run()
  File "/Users/chuck/Documents/patelco/monitor/dist/monitor.app/Contents/Resources/__boot__.py", line 82, in _run
    exec(compile(source, path, 'exec'), globals(), globals())
  File "/Users/chuck/Documents/patelco/monitor/dist/monitor.app/Contents/Resources/monitor.py", line 82, in <module>
    send_text_message(report_text)
  File "/Users/chuck/Documents/patelco/monitor/dist/monitor.app/Contents/Resources/monitor.py", line 46, in send_text_message
    message = client.messages.create(to="+1510845xxxx", from_="+1415758xxxx", body=msg)
  File "twilio/rest/api/v2010/account/message/__init__.pyc", line 92, in create
  File "twilio/base/version.pyc", line 205, in create
  File "twilio/base/version.pyc", line 47, in request
  File "twilio/base/domain.pyc", line 46, in request
  File "twilio/rest/__init__.pyc", line 122, in request
  File "twilio/http/http_client.pyc", line 68, in request
  File "requests/sessions.pyc", line 618, in send
  File "requests/adapters.pyc", line 407, in send
  File "requests/adapters.pyc", line 226, in cert_verify
OSError: Could not find a suitable TLS CA certificate bundle, invalid path: /Users/chuck/Documents/patelco/monitor/dist/monitor.app/Contents/Resources/lib/python35.zip/certifi/cacert.pem

Solution

  • This was a bug in requests that was recently fixed but has not made it to a release version yet. If you are ok with using a development version of requests, you can install from the github repo (upgrading if already present) so that when you build your app you have the latest version with this fix:

    pip install -U https://github.com/requests/requests/zipball/master