V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
qazwsxkevin
V2EX  ›  Python

Win7 有“本地连接”和"TAP",“WLAN",一共三个网络适配器,写 Python 遇上了这个问题困扰,目前无法解决。。。

  •  
  •   qazwsxkevin · 2020-05-12 18:39:54 +08:00 · 2302 次点击
    这是一个创建于 1445 天前的主题,其中的信息可能已经有所发展或是发生改变。

    首先:
    PC 上装了 open*pn,连到公司(国内)的内网网段上,PC 创建有"TAP-Win32 Adapter V9"这个网络适配器,这个是不能去改变”有或者无“的前提,但允许去改变这个适配器的参数。。。

    代码里用了 request-html 这个已经过时的库(这个一时间无法改变)

    情况: 如果 TAP 适配器 enable 了,request-html 去获取网页,是 Timeout,tcp closed 的。
    ( by the way:这个pn 并不推送 0.0.0.0 的路由给本地,只是推送了公司内部网段的路由过来,所以 PC 机的路由 0/0,基本上还是全往本地网关走,而不是全走公司pn 了)

    如果把 net stop Open*PNService,关闭了服务,
    request-html 一切正常

    所以基本上能判断,pycharm 写的 python,肯定是首选了 TAP 适配器走流量, 尽管我尝试了这个方法把 TAP 设备调整到最后了,但依然情况依旧 http://www.xitongcheng.com/jiaocheng/win7_article_46610.html

    所以现在开着*PN,就无法进行 python 做 request-html 操作了, 请教大家,这个问题如何解决?

    这个是 WIN7 系统调整的问题
    还是 request-html 的网络接口机制问题?

    6 条回复    2020-05-13 19:46:53 +08:00
    chinawrj
        1
    chinawrj  
       2020-05-12 19:04:20 +08:00
    通信时 bind 了 TAP 的 IP 地址?用 0.0.0.0 试试
    1462326016
        2
    1462326016  
       2020-05-13 09:32:09 +08:00
    也许你可以尝试修改本地路由,让你想访问的地址走本地适配器。
    我之前尝试过同事了连接两个适配器,一个内网,一个外网,调整了本地路由就可以了。
    仅供参考
    ghostwwg
        3
    ghostwwg  
       2020-05-13 10:06:10 +08:00
    看着感觉像是 open*** 拨号后修改了默认路由。拨号后默认流量走哪里?
    ghostwwg
        4
    ghostwwg  
       2020-05-13 10:06:51 +08:00
    @ghostwwg 审题不清,抱歉。
    julyclyde
        5
    julyclyde  
       2020-05-13 12:20:28 +08:00
    “肯定是”这话可不能随便说
    建议你抓包验证一下
    qazwsxkevin
        6
    qazwsxkevin  
    OP
       2020-05-13 19:46:53 +08:00
    谢谢各位大佬热心解答~

    问题已经得到解决,是 pyppeteer 的问题,根据
    https://github.com/psf/requests-html/issues/278#issuecomment-476950656
    这个答案,增加\pyppeteer\launcher.py 的 108,109 行
    ```
    #add following two lines
    '--proxy-server="direct://"',
    '--proxy-bypass-list=*'
    ```

    问题彻底解决!

    应该是 pyppeteer 自身缺陷的问题,时间水平所限,搞不懂机制的原理,解决问题就这样了,赶紧上车赶路才是正事
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2847 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:29 · PVG 14:29 · LAX 23:29 · JFK 02:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.