Python whois在转换为exe后失败



我是python的新手,几周前刚刚开始使用它,作为一个项目,我编写了一个程序来帮助我所在部门的代理进行主机、whois和mx查找。

以.py的形式运行程序,一切正常。但是,当我使用auto_py_to_exe或pyinstaller将.py转换为exe时,host和mx功能可以工作,但whois部分失败,并出现以下错误:

DNS查询名称不存在:[Erno 2]没有这样的文件或目录:"C:\Users\shawn\AppData\Local\Temp\_MEI109402\whois\data\public_suffix_list.dat">

在独自寻找答案后,我不知所措。我想我错过了一些简单的东西。任何帮助都会很棒。

我的进口:

import PySimpleGUI as sg
import dns.resolver
import socket
import whois
import pywhois

有问题的代码:

def whois_lookup():
# Get Whois data
try:
hostName = values["-getHost-"]
w = whois.whois(hostName)
tld = hostName.split(".")[-1]
nameservers = dns.resolver.query(hostName, "NS")
if tld == "ca":
window["-textbox-"].print("Registrar: ", w.registrar, "nExpiration Date: ", w.expiration_date, "n",)
window["-textbox-"].print("Name Servers: ")
for data in nameservers:
window["-textbox-"].print(data)
else: # same for now but .ca and the other tld's are different in how they display their data.
window["-textbox-"].print("Registrar: ", w.registrar, "nExpiration Date: ", w.expiration_date, "n",)
window["-textbox-"].print("Name Servers: ")
for data in nameservers:
window["-textbox-"].print(data)
except Exception as err:
window["-textbox-"].print("The DNS query name does not exist: ", err)
return()

完整的代码可以在这里找到

如果需要,自动复制输出

Running auto-py-to-exe v2.11.0
Building directory: C:UsersshawnAppDataLocalTemptmpx4w5o9ae
Provided command: pyinstaller --noconfirm --onefile --windowed --exclude-module "_bootlocale"  "C:/Users/shawn/Documents/GitHub/pythonProjects/dnsQuery.py"
Recursion Limit is set to 5000
Executing: pyinstaller --noconfirm --onefile --windowed --exclude-module _bootlocale C:/Users/shawn/Documents/GitHub/pythonProjects/dnsQuery.py --distpath C:UsersshawnAppDataLocalTemptmpx4w5o9aeapplication --workpath C:UsersshawnAppDataLocalTemptmpx4w5o9aebuild --specpath C:UsersshawnAppDataLocalTemptmpx4w5o9ae
48597 INFO: PyInstaller: 4.7
48612 INFO: Python: 3.8.12 (conda)
48632 INFO: Platform: Windows-10-10.0.19042-SP0
48644 INFO: wrote C:UsersshawnAppDataLocalTemptmpx4w5o9aednsQuery.spec
48665 INFO: UPX is not available.
48681 INFO: Extending PYTHONPATH with paths
['C:\Users\shawn\Documents\GitHub\pythonProjects']
49145 INFO: checking Analysis
49147 INFO: Building Analysis because Analysis-00.toc is non existent
49152 INFO: Initializing module dependency graph...
49165 INFO: Caching module graph hooks...
49213 INFO: Analyzing base_library.zip ...
53111 INFO: Processing pre-find module path hook distutils from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-distutils.py'.
53116 INFO: distutils: retargeting to non-venv dir 'C:\Users\shawn\miniconda3\envs\devops\lib'
57286 INFO: Caching module dependency graph...
57644 INFO: running Analysis Analysis-00.toc
57685 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:Usersshawnminiconda3envsdevopspython.exe
58179 INFO: Analyzing C:UsersshawnDocumentsGitHubpythonProjectsdnsQuery.py
59293 INFO: Processing pre-find module path hook site from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\pre_find_module_path\hook-site.py'.
59297 INFO: site: retargeting to fake-dir 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\fake-modules'
61684 INFO: Processing module hooks...
61698 INFO: Loading module hook 'hook-dns.rdata.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
65332 INFO: Processing pre-safe import module hook six.moves from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\pre_safe_import_module\hook-six.moves.py'.
65705 INFO: Loading module hook 'hook-pycparser.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
65711 INFO: Loading module hook 'hook-difflib.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65726 INFO: Loading module hook 'hook-distutils.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65731 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65743 INFO: Loading module hook 'hook-encodings.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65877 INFO: Loading module hook 'hook-heapq.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65890 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65979 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
65990 INFO: Loading module hook 'hook-pickle.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
66000 INFO: Loading module hook 'hook-pkg_resources.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
66511 INFO: Processing pre-safe import module hook win32com from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\_pyinstaller_hooks_contrib\hooks\pre_safe_import_module\hook-win32com.py'.
66843 WARNING: Hidden import "pkg_resources.py2_warn" not found!
66850 WARNING: Hidden import "pkg_resources.markers" not found!
66873 INFO: Loading module hook 'hook-setuptools.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
68043 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
68056 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
68062 INFO: Loading module hook 'hook-xml.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
68172 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
68393 INFO: checking Tree
68398 INFO: Building Tree because Tree-00.toc is non existent
68405 INFO: Building Tree Tree-00.toc
68595 INFO: checking Tree
68600 INFO: Building Tree because Tree-01.toc is non existent
68607 INFO: Building Tree Tree-01.toc
68759 INFO: checking Tree
68763 INFO: Building Tree because Tree-02.toc is non existent
68770 INFO: Building Tree Tree-02.toc
68804 INFO: Loading module hook 'hook-Crypto.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\_pyinstaller_hooks_contrib\hooks\stdhooks'...
68833 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks'...
68929 INFO: Looking for ctypes DLLs
69058 INFO: Analyzing run-time hooks ...
69083 INFO: Including run-time hook 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgutil.py'
69098 INFO: Including run-time hook 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_multiprocessing.py'
69114 INFO: Including run-time hook 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_inspect.py'
69127 INFO: Including run-time hook 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth__tkinter.py'
69140 INFO: Including run-time hook 'C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\hooks\rthooks\pyi_rth_pkgres.py'
69174 INFO: Looking for dynamic libraries
69834 INFO: Looking for eggs
69838 INFO: Using Python library C:Usersshawnminiconda3envsdevopspython38.dll
69847 INFO: Found binding redirects: 
[]
69866 INFO: Warnings written to C:UsersshawnAppDataLocalTemptmpx4w5o9aebuilddnsQuerywarn-dnsQuery.txt
70027 INFO: Graph cross-reference written to C:UsersshawnAppDataLocalTemptmpx4w5o9aebuilddnsQueryxref-dnsQuery.html
70117 INFO: checking PYZ
70126 INFO: Building PYZ because PYZ-00.toc is non existent
70136 INFO: Building PYZ (ZlibArchive) C:UsersshawnAppDataLocalTemptmpx4w5o9aebuilddnsQueryPYZ-00.pyz
71585 INFO: Building PYZ (ZlibArchive) C:UsersshawnAppDataLocalTemptmpx4w5o9aebuilddnsQueryPYZ-00.pyz completed successfully.
71638 INFO: checking PKG
71643 INFO: Building PKG because PKG-00.toc is non existent
71657 INFO: Building PKG (CArchive) dnsQuery.pkg
77419 INFO: Building PKG (CArchive) dnsQuery.pkg completed successfully.
77497 INFO: Bootloader C:Usersshawnminiconda3envsdevopslibsite-packagesPyInstallerbootloaderWindows-64bitrunw.exe
77502 INFO: checking EXE
77519 INFO: Building EXE because EXE-00.toc is non existent
77524 INFO: Building EXE from EXE-00.toc
77536 INFO: Copying bootloader EXE to C:UsersshawnAppDataLocalTemptmpx4w5o9aeapplicationdnsQuery.exe
77652 INFO: Copying icon to EXE
77662 INFO: Copying icons from ['C:\Users\shawn\miniconda3\envs\devops\lib\site-packages\PyInstaller\bootloader\images\icon-windowed.ico']
77768 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
77776 INFO: Writing RT_ICON 1 resource with 3752 bytes
77786 INFO: Writing RT_ICON 2 resource with 2216 bytes
77796 INFO: Writing RT_ICON 3 resource with 1384 bytes
77818 INFO: Writing RT_ICON 4 resource with 38188 bytes
77833 INFO: Writing RT_ICON 5 resource with 9640 bytes
77839 INFO: Writing RT_ICON 6 resource with 4264 bytes
77845 INFO: Writing RT_ICON 7 resource with 1128 bytes
77858 INFO: Copying 0 resources to EXE
77867 INFO: Emedding manifest in EXE
77881 INFO: Updating manifest in C:UsersshawnAppDataLocalTemptmpx4w5o9aeapplicationdnsQuery.exe
77979 INFO: Updating resource type 24 name 1 language 0
77995 INFO: Appending PKG archive to EXE
84755 INFO: Building EXE from EXE-00.toc completed successfully.
Moving project to: C:UsersshawnDesktop
Complete.

whois模块包括一个数据文件data/public_suffix_list.dat。您需要将其作为外部数据项添加到pyinstaller指令文件中。他们本应该把它变成一个Python模块。

由于海报蒂姆·罗宾斯和OP之间的对话有点无人看管。通过修改生成的pyinstaller规范文件,我可以让它和ONEFILE一样工作。

对于其他需要解决此问题(或类似问题(的人。我建议您生成规范文件(请参阅PyInstaller文档,但它要么是pyi-makespec --onefile pythonprogram.py,要么类似(,然后按照下面的类似内容进行操作。出于我的目的,我正在使用一个创建virtualenv的项目(通过应用程序pipfile,而不是像往常一样手动virtualenv,但这应该不会有什么不同。(

生成规范文件后,您应该在编辑器中打开它。在中的规范文件中,您将看到一个类似的对象:

a = Analysis(
['spa.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False,
)

您应该将data变量编辑为类似的格式,但使用存储public_suffix_list.dat的各自的virtualenv python路径和预期的复制目标。确保它是一个元组,并确保复制目标只是目标目录。

datas=[('/home/newguy/.local/share/virtualenvs/Shepherd-vciLSPug/lib/python3.8/site-packages/whois/data/public_suffix_list.dat', './whois/data/')

然后运行正常的pyinstaller pythonprogram.spec生成单个可执行文件。

相关内容

最新更新