【发布时间】:2018-02-08 08:25:02
【问题描述】:
我有一个通过代理服务器访问 Internet 的程序,我正在使用 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 一起工作?
【问题讨论】:
标签: python python-3.x httprequest pyinstaller proxy-server