首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PyPac PyInstaller无法访问internet

PyPac PyInstaller无法访问internet
EN

Stack Overflow用户
提问于 2018-02-08 16:25:02
回答 2查看 661关注 0票数 1

我有一个通过代理服务器访问互联网的程序,我正在使用PyPac的PACSession进行会话。当我使用python调用程序时,这个方法工作得很好。但是,使用pyinstaller编译它会给我一个错误。

测试程序:

代码语言:javascript
运行
复制
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())

版本:

代码语言:javascript
运行
复制
Windows 7
python 3.6.3 
pypack 0.5.0
pyinstaller 3.3
requests 2.18.4
tld 0.7.9; 

错误:

代码语言:javascript
运行
复制
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一起工作?

EN

回答 2

Stack Overflow用户

发布于 2018-02-28 12:36:38

您的实际问题是:

代码语言:javascript
运行
复制
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二进制文件中。

代码语言:javascript
运行
复制
datas: [('C:\Python\Lib\site-packages\tld\res\effective_tld_names.dat.txt', 'tld\res')]
票数 1
EN

Stack Overflow用户

发布于 2019-01-28 20:26:26

如果您尝试从上面复制粘贴解决方案,请回答不起作用,请尝试此操作,并确保适当更改您的python路径

代码语言:javascript
运行
复制
datas= [('C:\\Python\\Lib\\site-packages\\tld\\res\\effective_tld_names.dat.txt', 'tld\\res')]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48680798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档