question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

selenium-wire won't work when python script is compiled with pyarmor

See original GitHub issue

Hello,

I am currently working on one of my projects and I need seleniumwire in order to monitor requests. It seems to work perfectly while the script is running in .py and inside my IDE, but once I compile the script, I get an error and it won’t start.

Error in question: cannot import name 'webdriver' from 'seleniumwire' (C:\Users\USER\AppData\Local\Temp\2\_MEI48042\seleniumwire\__init__.pyc)

I am using hidden imports to pack my program, and I think I might be missing something that makes seleniumwire not work at all. Does anyone know the hidden import list required for seleniumwire (if there’s one) ? I would love to use it.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dharmey747commented, Sep 1, 2021

I have just tested this and it seems to work perfectly (even tho Pyinstaller was throwing a lot of errors for some reason, everything works fine). Thank you so much for your help!

1reaction
wkeelingcommented, Aug 30, 2021

Sorry for the delay in replying on this.

I’ve had a play around with pyarmor and pyinstaller and I’ve managed to get a test script to work. To begin with it was giving me the exact same error as you reported cannot import name 'webdriver' from 'seleniumwire' ... but I found I had to use the --collect-all option to pyinstaller to get things to work.

To create the obfuscated script:

pyarmor obfuscate --enable-suffix --obf-code 2 --advanced 2 --output dist/obf --package-runtime 0 main.py

To create the binary with pyinstaller:

pyinstaller --onefile --collect-all seleniumwire main.py

My main.py is a simple script that starts a webdriver instance and requests the wikipedia site, before printing the number of requests and ending:

import logging
from seleniumwire import webdriver
logging.basicConfig(level=logging.INFO)

if __name__ == '__main__':
    driver = webdriver.Chrome()
    driver.get('https://www.wikipedia.org/')
    print(f'Captured {len(driver.requests)} requests')
    driver.quit()
Read more comments on GitHub >

github_iconTop Results From Across the Web

When Things Go Wrong — PyArmor 6.7.0 documentation
The obfuscated script is a very simple Python script, the first line is an import ... As obfuscating the script by pyarmor ,...
Read more >
Trying to use Pyarmor code in python · Issue #265 - GitHub
Hello How can i use pyarmor code in python for eg. subprocess.call("pyarmor pack -e " --onefile --noconsole " + path) I am trying...
Read more >
Can't access website with Selenium-wire after using Pyinstaller
I found the solution if someone else has this issue. Go to your python folder, and find the pyinstaller hooks folder, for me...
Read more >
How to Obfuscate Python Scripts With PyArmor
The problem with distributing classic Python programs is that anyone can open the files in an editor and read the source code, possibly ......
Read more >
Newest 'pyinstaller' Questions - Stack Overflow
I tried pyarmor but to open this file you have to use pytransform. ... os.startfile() doesn't work after compiling python script with pyinstaller....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found