我有一个通过代理服务器访问互联网的程序,我正在使用PyPac的PACSession进行会话。当我使用python调用程序时,这个方法工作得很好。但是,使用pyinstaller编译它会给我一个错误。
测试程序:
import sys
import os
from pypac import PACSession
from requests.auth import HTTPProxyAuth
import getpass
import keyring
url = r'https://leilookup.gleif.org/api/v1/leirecords?lei='
lei_list = ['I9O8MELCUVOTLJABOX92', '5493004NRE4TCTRC2D29', 'VBHFXSYT7OG62HNT8T76', '529900M2YBAPOUTTM178', '549300KJFL0KHN20KH82',
'0NTV4GLMGXKW55GJC835']
def main():
lei_numbers = ",".join(lei_list)
internet = 'gleif.org'
password = keyring.get_password(internet, getpass.getuser())
if not password:
keyring.set_password(internet, getpass.getuser(), getpass.getpass('Please enter your Login password: '))
print('Before PACSession')
session = PACSession(proxy_auth=HTTPProxyAuth(getpass.getuser(), keyring.get_password(internet, getpass.getuser())))
page = session.get(url=url + lei_numbers)
json = page.json()
for ix in range(len(json)):
print(json[ix]['LEI']['$'] + ': ' + json[ix]['Entity']['LegalName']['$'])
return 0
if __name__ == "__main__":
sys.exit(main())
版本:
Windows 7
python 3.6.3
pypack 0.5.0
pyinstaller 3.3
requests 2.18.4
tld 0.7.9;
错误:
Traceback (most recent call last):
File "site-packages\tld\utils.py", line 117, in get_tld_names
File "c:\python36\lib\codecs.py", line 895, in open
file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: '...\\AppData\\Local\\Temp\\_MEI299882\\tld\\res\\effective_t
ld_names.dat.txt'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "urllib\request.py", line 1318, in do_open
File "http\client.py", line 1239, in request
File "http\client.py", line 1285, in _send_request
File "http\client.py", line 1234, in endheaders
File "http\client.py", line 1026, in _send_output
File "http\client.py", line 964, in send
File "http\client.py", line 936, in connect
File "socket.py", line 724, in create_connection
File "socket.py", line 713, in create_connection
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of ti
me, or established connection failed because connected host has failed to respond
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "site-packages\tld\utils.py", line 74, in update_tld_names
File "urllib\request.py", line 223, in urlopen
File "urllib\request.py", line 526, in open
File "urllib\request.py", line 544, in _open
File "urllib\request.py", line 504, in _call_chain
File "urllib\request.py", line 1346, in http_open
File "urllib\request.py", line 1320, in do_open
urllib.error.URLError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly resp
ond after a period of time, or established connection failed because connected host has failed to respond>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ScreenScraping.py", line 51, in <module>
File "ScreenScraping.py", line 41, in main
File "site-packages\requests\sessions.py", line 521, in get
File "site-packages\pypac\api.py", line 179, in request
File "site-packages\pypac\api.py", line 244, in get_pac
File "site-packages\pypac\api.py", line 48, in get_pac
File "site-packages\pypac\api.py", line 72, in collect_pac_urls
File "site-packages\pypac\wpad.py", line 31, in proxy_urls_from_dns
File "site-packages\tld\utils.py", line 169, in get_tld
File "site-packages\tld\utils.py", line 124, in get_tld_names
File "site-packages\tld\utils.py", line 84, in update_tld_names
tld.exceptions.TldIOError: <urlopen error [WinError 10060] A connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because connected host has failed to respond>
[29744] Failed to execute script ScreenScraping
我可以做什么来使编译的程序与pyinstaller一起工作?
发布于 2018-02-28 12:36:38
您的实际问题是:
FileNotFoundError: [Errno 2] No such file or directory: '...\\AppData\\Local\\Temp\\_MEI299882\\tld\\res\\effective_tld_names.dat.txt'
基本上,pypac
使用的tld
包加载该文本文件,一旦用PyInstaller打包,该文件就不再可用。可以使用--add-data
标志或等级库文件中的datas
字段将其包含在PyInstaller二进制文件中。
datas: [('C:\Python\Lib\site-packages\tld\res\effective_tld_names.dat.txt', 'tld\res')]
发布于 2019-01-28 20:26:26
如果您尝试从上面复制粘贴解决方案,请回答不起作用,请尝试此操作,并确保适当更改您的python路径
datas= [('C:\\Python\\Lib\\site-packages\\tld\\res\\effective_tld_names.dat.txt', 'tld\\res')]
https://stackoverflow.com/questions/48680798
复制相似问题