推荐学习书目
› 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
JCZ2MkKb5S8ZX9pq
V2EX  ›  Python

Python requests mac 版代理忽然挂不上了?

  •  
  •   JCZ2MkKb5S8ZX9pq · Jan 11, 2019 · 1645 views
    This topic created in 2861 days ago, the information mentioned may be changed or developed.
    # 以前用这个方法可以
    proxy = {"http":"socks5://127.0.0.1:1080","https":"socks5://127.0.0.1:1080"}
    
    # 现在 PC 版用这个可以
    proxy = {"http":"127.0.0.1:1080","https":"127.0.0.1:1080"}
    
    # MAC 版两种都不行(以前第一种行)
    

    不知道啥时候发生的这个情况,反正搞了半天没搞成。
    两个电脑装的包都一样的。requests[socks] 和 pysocks 都装了且升级了。
    代理用的 ss,PC 版 4.1.3.1,MAC 版 2.6.3,浏览器访问都正常通过。

    • PC。浏览器设置 http 或者 socks5 都能通过,python 里只能不加 socks5,加了通不过。
    • MAC。浏览器设置 http 通不过,socks5 可以通过。python 里都不行。

    是不是我还漏了啥了?

    Supplement 1  ·  Jan 11, 2019

    换了 ssx-ng 终于搞好了,有几点不同:

    • ssx-ng 一定要开启。
      ssx-ng的manual模式,类似于win版ss的关闭(未启用系统/自动代理,但仍在运行)。
      之前mac版ssx的时候可以选关闭,不影响chrome访问,但ng关了好像就不行了。
    • ssx-ng也支持http代理,但http/socks/pac三个端口要区分。
      (win版好像http和socks5我都连1080也能连上)

    满足以上两点,PAC/Global/手动三个随意,跟之前一样指定proxy,requests就可以连上了。
    为了多平台统一,我用的http的1080端口。
    {"http":"127.0.0.1:1080","https":"127.0.0.1:1080"}

    测试方法是观察 ssx-ng的设置 和 系统/网络设置/代理 之间的关联。
    然后先通过safari走系统代理测试连通情况。

    6 replies  •  2019-01-11 18:05:22 +08:00
    JCZ2MkKb5S8ZX9pq
    JCZ2MkKb5S8ZX9pq
    OP
    Jan 11, 2019
    1
    看了下,Mac 下用
    ```
    proxy = {"http":"socks5://127.0.0.1:1080","https":"socks5://127.0.0.1:1080"}
    ```
    上 ip.cn 可以看到 ip 已经是海外的了,连 baidu 也连得上( http/https 都可以)。
    但是连外网还是都连不上(浏览器内都可以)。
    bantao
    bantao
    Jan 11, 2019
    2
    测试 windows py3.6 requests socks5 (无认证) 没问题,你那边报什么错
    cdlixucd
    cdlixucd
    Jan 11, 2019
    3
    下载一个软件不是很方便吗?非要搞配置文件
    JCZ2MkKb5S8ZX9pq
    JCZ2MkKb5S8ZX9pq
    OP
    Jan 11, 2019
    4
    @bantao 我 win 的 http 没问题,socks 不晓得为啥不行,mac 上一团问题,不知道是系统更新还是咋的。现在换了 ss-ng 在试。
    youthfire
    youthfire
    Jan 11, 2019
    5
    具体不理解,以前作 gmail 发邮件的程序时我是这样写的,给你参考,python3

    from httplib2 import socks
    import socket

    socket.socket = socks.socksocket
    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,"127.0.0.1",1080)
    JCZ2MkKb5S8ZX9pq
    JCZ2MkKb5S8ZX9pq
    OP
    Jan 11, 2019
    6
    @youthfire 嗯 实在不行只能用其它库试了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2335 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 11:23 · PVG 19:23 · LAX 03:23 · JFK 06:23
    ♥ Do have faith in what you're doing.