PyWin32 throws “pywintypes com_error call was rejected” error, but only when NOT running from CMD

System setups:

  • Development PC: Win 10,Python 3.7.7, PyInstaller 5.3.12
  • Deployment PC: Win11, No Python installled

I’ve made a CLI python script (running from Windows CMD) with the following simple logic:

  • When started, open a TKinter’s “Select file” GUI dialogue wiht filedialog.askopenfilename()
  • Once .xlsx file has been selected, open MSExcel with win32com.client.Dispatch('Excel.Application')
  • Then enter a while(1) loop in the background, waiting for the user to press Spacebar
  • When user presses spacebar, write a number to Excel’s active cell with ExcelApp.ActiveCell.Value = <some number>
  • Move the active cell “cursor” inside Excel down by 1 row with ExcelApp.ActiveCell.GetOffset(1,0).Select()

When ran as a .py with python myScript.py, it works 100% as intended without errors. Script could even write values to .xlsx files that user opens from OneDrive integration folders. All good.

However, the Win11 PC that the script is supposed to be deployed to has no Python installed. Let’s assume that Python cannot be installed on that PC at all due to i.e. no admin rights.

Therefore I packaged the script as a standalone .EXE with Pyinstaller using:

python -m PyInstaller --noconfirm --onedir --console "myScript.py"

The deployment to the Win11 pc was done in January, 2024. The packed .exe version of the script worked absolutely fine without ANY problems throughout the entire year.

Then, on 27th of December 2024 it decides to randomly out of the blue throw the following exception:

File "win32comclientdynamic.py line 627, in _getattr__
pywintypes com_error: (-2147418111, 'Call was rejected by callee, none, none)

I immediately run a number of tests:

  1. Copy the myScript.exe from Deployment to Dev machine and run it there. PASS.
  2. Re-build the last version of the .py script with PyInstaller on the Dev Machine, then copy .exe to deployment PC and run. FAIL! Same Exception.
  3. Re-build the last version of the .py script with PyInstaller on the Dev Machine, then copy it to deployment PC and run it with CMD. PASS

The pattern seemed totally random and non-deterministic. I was considering starting a prayer to please the Machine Spirits when I noticed, that the .exe runs inside something called a “Terminal”.

Now, it must be said I haven’t worked with Win 11 that much. Digging some more, I figured out that:

  • “Terminal” is a “shell-shell” that is used by Win11 to run whatever would be ran inside CMD in 7/10.
  • Win11’s Terminal starts PowerShell by default.
  • Powershell is the reason the exception occurs, as it does NOT occur if .exe is ran with CMD.

I’ve quickly made a “fix” in a form of a .bat file that runs the .exe inside a CMD. But that is not the proper solution.

What are the reasons for:

  • Win11 Terminal using Powershell by default for CLI apps? Powershell and CMD are very different by nature, and compatibility is not guaranteed…
  • Powershell causing the “Call rejected by callee” exception in win32com? Security/execution policy? I’ve found similar question here, but it does the workaround only and does not provide the details as to why.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật