Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

ca cert not found for compiled python script #310

Closed
CheemaOTB opened this issue Jun 4, 2021 · 3 comments
Closed

ca cert not found for compiled python script #310

CheemaOTB opened this issue Jun 4, 2021 · 3 comments

Comments

@CheemaOTB
Copy link

I compiled a python script that was using selenium wire so that my friend could use it but he gets this error.

[21:41:56.795873] [Task 1] An Error Occured
Exception in thread Thread-1:
Traceback (most recent call last):
  File "<frozen ssense>", line 318, in main
  File "undetected_chromedriver__init.py", line 53, in new
  File "seleniumwire\webdriver.py", line 90, in init
  File "seleniumwire\backend.py", line 35, in create
  File "seleniumwire\server.py", line 28, in init__
  File "seleniumwire\utils.py", line 95, in extract_cert_and_key
  File "pkgutil.py", line 638, in get_data
  File "PyInstaller\loader\pyimod03_importers.py", line 365, in get_data
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\ower\AppData\Local\Temp\_MEI115042\seleniumwire\ca.crt'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "threading.py", line 950, in _bootstrap_inner
  File "threading.py", line 888, in run
  File "<frozen ssense>", line 327, in main
UnboundLocalError: local variable 'driver' referenced before assignment
@CheemaOTB
Copy link
Author

My dirty solution: add ca.crt and ca.key from https://github.com/wkeeling/selenium-wire/tree/master/seleniumwire in soft AppData folder

Did you put it in this directory "C:\Users\Owner\AppData\Roaming"?

@binchoo
Copy link

binchoo commented Aug 7, 2021

@CheemaOTB
Hello, I am also hearing from some users that they are experiencing the same issue. Where should ca.crt and ca.key be placed?

@binchoo
Copy link

binchoo commented Aug 7, 2021

Solution

Make the Pyinstaller include seleniumwire's ca.crt and ca.key manually.

Using pyi-makespec, we can create and edit a .spec file to inject here a list of dependent static resources. (See, Using Spec Files)

For example, this code is injecting the dependant resources to the datas argument when creating an Analysis object.

from os.path import join, dirname, abspath, split
from os import sep
import glob
import seleniumwire

pkg_dir = split(seleniumwire.__file__)[0]
pkg_data = []
pkg_data.extend((file, dirname(file).split("site-packages")[1]) for file in glob.iglob(join(pkg_dir,"**{}*".format(sep)), recursive=True))

a = Analysis([f'..{os.sep}qtmain.py'],
             pathex=['F:\\repositories\\corona-virus-vaccine-reservation'],
             binaries=[],
             datas=pkg_data,
             hiddenimports=[],

(Here the actual code.)

Then, finally, we can build an executable file from the .spec file with a command like pyinstaller foobar.spec.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants