I got this error! OSError: [WinError 193] %1 is not a valid Win32 application
Asked Answered
A

7

8

I trying to run an Python file today and got this error below! Anyone know what's issue and the solution to fix it?

Traceback (most recent call last):
  File "C:\Users\Al PC\PycharmProjects\Fe\report_auto-final-v2.7.py", line 60, in <module>
    driver = webdriver.Chrome(service=chrome_service, options=options)  # ChromeDriverManager()
  File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
    super().__init__(
  File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 53, in __init__
    self.service.start()
  File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\common\service.py", line 105, in start
    self._start_process(self._path)
  File "C:\Users\Al PC\PycharmProjects\SocialMedia\venv\lib\site-packages\selenium\webdriver\common\service.py", line 206, in _start_process
    self.process = subprocess.Popen(
  File "C:\Users\Al PC\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\Al PC\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

Process finished with exit code 1
Audraaudras answered 26/7, 2024 at 7:47 Comment(3)
Please show the relevant part of report-auto-final-v2.7.pyAlbite
This question is similar to: OSError: [WinError 193] %1 is not a valid Win32 application. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.Mailemailed
I have edited it with more specific code. Hope some can help me.Audraaudras
C
22

If you construct the service like this:

service = ChromeService(ChromeDriverManager().install())

I noticed ChromeDriverManager().install() returns <path stuff>\chromedriver-win32\THIRD_PARTY_NOTICES.chromedriver instead of the chromedrive.exe.

This works for me:

chrome_install = ChromeDriverManager().install()

folder = os.path.dirname(chrome_install)
chromedriver_path = os.path.join(folder, "chromedriver.exe")

service = ChromeService(chromedriver_path)
Cornish answered 26/7, 2024 at 9:8 Comment(2)
Hi, in my case, which part below shall I change to make it work? options = Options() options.add_argument("--incognito") # incognito mode options.add_argument('ignore-certificate-errors') # if website have SSL error, this code will fix SSL Certificate requirement chrome_service = ChromeService(ChromeDriverManager().install()) chrome_service.creationflags = CREATE_NO_WINDOW # hide webdriver console driver = webdriver.Chrome(service=chrome_service, options=options) # ChromeDriverManager() driver.minimize_window() # minimized browser print('Chrome webdriver loaded')Audraaudras
Replace your: chrome_service = ChromeService(ChromeDriverManager().install()) with all the lines I posted, but change service = ChromeService(chromedriver_path) to chrome_service = ChromeService(chromedriver_path)Cornish
T
2

Everyone, I'm sure you are facing a sudden problem and are having a lot of trouble,

but it turns out that this problem can be solved by updating the version of webdriver_manager.

  • My coding
import wx
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager

# Required for dialog box display
app = wx.App(0)

# Creating options
option = Options()

# To avoid "unknown error: net::ERR_CONNECTION_CLOSED"
option.add_argument('--disable-dev-shm-usage')

option.add_argument('no-sandbox')
option.add_argument('--disable-extensions')
option.add_argument('--disable-gpu')
option.add_argument('disable-infobars')
option.add_argument('--incognito') # secret mode

# Enable headless mode.
option.add_argument('--headless')

# Create a Chrome WebDriver object.
try:

# Process to automatically install the driver of the same version as Chrome on your PC.
    driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=option)

except Exception as e:
    print("error:", e)
    wx.MessageBox(f'{e}', u'error', wx.ICON_ERROR)
Traceback (most recent call last):
  File "c:\Users\iorin\OneDrive\Python_Scripts\formdemo\modules\chrome_driver.py", line 34, in <module>
    driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=option)
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\iorin\OneDrive\Python_Scripts\formdemo\main.py", line 12, in <module>
    from modules import (full_name,
  File "c:\Users\iorin\OneDrive\Python_Scripts\formdemo\modules\__init__.py", line 1, in <module>
    from . import (
  File "c:\Users\iorin\OneDrive\Python_Scripts\formdemo\modules\full_name.py", line 5, in <module>
    from . import (chrome_driver,
  File "c:\Users\iorin\OneDrive\Python_Scripts\formdemo\modules\chrome_driver.py", line 46, in <module>
    driver = webdriver.Chrome(ChromeDriverManager(res.text).install(),options=option)
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 76, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\iorin\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 114
Current browser version is 127.0.6533.89 with binary path C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

Step 1. Run the command pip show webdriver-manager.

Name: webdriver-manager
Version: 4.0.0
Summary: Library provides the way to automatically manage drivers for different browsers
Home-page: https://github.com/SergeyPirogov/webdriver_manager
Author: Sergey Pirogov
Author-email: [email protected]
License:
Location: c:\users\iorin\appdata\local\programs\python\python39\lib\site-packages
Requires: packaging, python-dotenv, requests
Required-by:

Step 2. Visit the author's site.

Step 3. Run the command pip install webdriver-manager==4.0.2 on See what changed .

Questions that were helpful▶ ChromerDriverManager not returning correct path for the chrome driver #665

Terracotta answered 11/8, 2024 at 16:27 Comment(0)
P
0
chrome_options = ChromeOptions()
chrome_options.add_argument("--headless=new")
driver = webdriver.Chrome(options=chrome_options)

It works on my programme. Just delete ChromeDriverManager().install() and ChromeService.

Poilu answered 30/7, 2024 at 21:30 Comment(0)
S
0

The problem is with the newest version of webdriver (or downloader).

Look into the file: c:\Users\<user>\.wdm\drivers.json

The new version section differs from the previous. "binary_path" points to "THIRD_PARTY_NOTICES.chromedriver" instead of "chromedriver.exe"

    "win64_chromedriver_126.0.6478.127_for_126.0.6478.127": {
        "timestamp": "17/07/2024",
        "binary_path": "C:\\Users\\JohnX\\.wdm\\drivers\\chromedriver\\win64\\126.0.6478.127\\chromedriver-win32/chromedriver.exe"
    },
    "win64_chromedriver_126.0.6478.182_for_126.0.6478.182": {
        "timestamp": "24/07/2024",
        "binary_path": "C:\\Users\\JohnX\\.wdm\\drivers\\chromedriver\\win64\\126.0.6478.182\\chromedriver-win32/chromedriver.exe"
    },
    "win64_chromedriver_127.0.6533.89_for_127.0.6533.89": {
        "timestamp": "05/08/2024",
        "binary_path": "C:\\Users\\JohnX\\.wdm\\drivers\\chromedriver\\win64\\127.0.6533.89\\chromedriver-win32/THIRD_PARTY_NOTICES.chromedriver"
    }

The solution provided by asdfa works as it replaces the path. You can also try to modify "drivers.json" file.

Sabrasabre answered 5/8, 2024 at 8:50 Comment(0)
A
0

I also came across this issue today. My setup looks like:

options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\usr\AppData\Local\Google\Chrome\User Data")
options.add_argument(r'--profile-directory=Profile 1')

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options) 

I get a similar error: OSError: [WinError 193] %1 is not a valid Win32 application when calling webdriver.Chrome() The code block was working fine just 18 days ago, but something must have changed.

This error was fixed using asdfa's solution by creating the service (path to driver exe) separately like so:

chrome_install = ChromeDriverManager().install()
folder = os.path.dirname(chrome_install)
chromedriver_path = os.path.join(folder, "chromedriver.exe")
service = webdriver.ChromeService(chromedriver_path)

options = webdriver.ChromeOptions()
options.add_argument(r"user-data-dir=C:\Users\usr\AppData\Local\Google\Chrome\User Data")
options.add_argument(r'--profile-directory=Profile 1')
driver = webdriver.Chrome(service = service, options = options)

Additionally, for MacOS, the executable is stored without the .exe so you must omit it.

Anaclinal answered 7/8, 2024 at 22:42 Comment(0)
N
0

"driver = webdriver.Chrome()" is a more modern method, so

simply replace:

driver=webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

with:

driver = webdriver.Chrome()
Nimesh answered 13/8, 2024 at 6:37 Comment(0)
P
-1

check your settings!

C:/Users/{user}/.wdm/drivers.json

Placidia answered 31/7, 2024 at 14:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.