3

I have a simple python 2.7 script using external module ("requests").. I'm using py2exe and having problem when running the exe.

test.py code:::

import requests
r = requests.get('https://api.github.com/')
print r.status_code
print r.text

setup.py code::::

from distutils.core import setup
import py2exe
setup(console=['youtube.py'], options = {'py2exe': { 'packages':['requests']}})

py2exe works for internal modules..but error for external modules.. error log::

D:\dist>youtube.exe
Traceback (most recent call last):
File "youtube.py", line 2, in <module>
File "requests\api.pyc", line 69, in get
File "requests\api.pyc", line 50, in request
File "requests\sessions.pyc", line 465, in request
File "requests\sessions.pyc", line 573, in send
File "requests\adapters.pyc", line 431, in send
requests.exceptions.SSLError: [Errno 2] No such file or directory
Mannan Raja
  • 51
  • 1
  • 2
  • Have you read [this post](http://stackoverflow.com/q/15157502/4154977)? – Thomas Lee Aug 29 '15 at 19:48
  • from cx_Freeze import setup, Executable import requests.certs build_exe_options = {"include_files":[(requests.certs.where(),'cacert.pem')]} setup( name = "foo", version = "1.1", description = "Description of the app here.", options = {"build_exe": build_exe_options}, executables = [Executable("test.py")] ) – Mannan Raja Aug 29 '15 at 20:52

2 Answers2

1

The problem is that the function requests.certs.where returns an incorrect path for a file named cacert.pem when its compiled. requests.utils.DEFAULT_CA_BUNDLE_PATH is set using requests.certs.where() and then that variable is imported by various other functions. To workaround this you can copy C:\Python27\Lib\site-packages\requests\cacert.pem to the directory containing your exe and then hard code that location to your requests.utils file

from os.path import join, abspath
DEFAULT_CA_BUNDLE_PATH = join(abspath('.'), 'cacert.pem')

or from your main module

import requests
from os.path import join, abspath
requests.utils.DEFAULT_CA_BUNDLE_PATH = join(abspath('.'), 'cacert.pem')
user2682863
  • 3,097
  • 1
  • 24
  • 38
-1

Kind of late to the response on this, but in your request try setting verify=False:

import requests
r = requests.get('https://api.github.com/', verify=False)
print r.status_code
print r.text
crookedleaf
  • 2,118
  • 4
  • 16
  • 38
  • 2
    are you seriously suggesting to turn off SSL-verification, just to get the script working? – umläute Feb 15 '17 at 13:45
  • @umläute unfortunately, i am. it's not the safest thing to do by any means, but this is a known issue with Py2EXE being used on code containing the requests library. – crookedleaf Mar 06 '17 at 23:15