S
S
shibanovan2016-04-28 10:48:27
Python
shibanovan, 2016-04-28 10:48:27

Py2exe exceptions SSLError how to win?

Compiling a simple python script to exe using py2exe. No errors on compilation, error on startup

requests.exceptions.SSLError: [Errno 2] No such file or directory

Google knows this error, as far as I understood from the discussions, the error is related to the cacert.pem file. Put it next to the exe - no change. Someone solved such a problem?
Here is the code I am compiling
# -*- coding: utf-8 -*-
from win32com import client
import telepot
import ConfigParser
import codecs
import os

config = ConfigParser.RawConfigParser()
config.readfp(codecs.open('config.ini', 'r', 'cp1251'))#Задаем имя ini-файла
path = config.get('main', 'path')
chatID = config.get('main', 'chatid')
print (path)
print (chatID)

#Last page xls 2 pdf
xlApp = client.Dispatch("Excel.Application")
books = xlApp.Workbooks.Open(path)
t= books.Worksheets.count  # количество листов
print(t)

ws = books.Worksheets[t-1]
n = ws.name # Имя листа
print (n)
report = 'C:\\test\\'+n+'.pdf'
ws.Visible = 1
ws.ExportAsFixedFormat(0, report)
books.Close()
xlApp.Quit()

####telegram
TOKEN = '207266730:AAF5BXGKTIEmS8-RbwCqXPcCKnL7yorhmP4'
bot = telepot.Bot(TOKEN)
f = open(report, 'rb')  # some file on local disk
n2 = "Отчет "
n2UTF = unicode(n2, 'utf-8', errors='replace')
Text = n2UTF + n
message = bot.sendMessage(chatID,Text)
response = bot.sendDocument(chatID, f)
print(response)
print report
f.close()
os.remove(report)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Novikov, 2016-04-28
@BOOMER_74

I solved it, but only did it with cx_Freeze. Everything was solved by writing a small module ca_certs_locater:

import os
import sys

def get():
  return os.path.join(os.path.dirname(os.path.abspath(sys.executable if getattr(sys, "frozen", False) else __file__)), "cacerts.txt")

The build script looks like this:
import os

import httplib2
from cx_Freeze import setup, Executable

setup(
  name="Name",
  version="1.0.0",
  description="Description",
  options={
    "build_exe": {
      "packages": [
        "ca_certs_locater", ...
      ],
      "include_files": [
        os.path.join(os.path.dirname(os.path.abspath(httplib2.__file__)), "cacerts.txt"),
        ...
      ],
      "excludes": [
        "tkinter"
      ]
    }
  },
  executables=[
    Executable("ExecutableFileName.py")
  ]
)

The only BUT: this is applicable when using httplib2. In other cases, you need to find the place in the library where the path to cacerts is indicated and change it to the desired one (perhaps there is the same hook as httplib2).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question