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
xiaohundun
V2EX  ›  Python

Tor 求助

  •  
  •   xiaohundun · 163 天前 · 799 次点击
    这是一个创建于 163 天前的主题,其中的信息可能已经有所发展或是发生改变。

    为什么 https://httpbin.org/get 这个地址我在 tor 中可以匿名访问但是在 python 里使用 tor 的 socks 代理的时候就不行呢?

    代码:

    
    def switch_proxy():
        """
        切换 Tor 代理地址
        :return: NULL
        """
        with Controller.from_port(port=9151) as controller:
            controller.authenticate()
            if controller.is_newnym_available():
                print("hi")
                controller.signal(Signal.NEWNYM)  # type: ignore
    
    
    for i in range(10):
        switch_proxy()
        print(1)
        proxies = {"http": "socks5://127.0.0.1:9150", "https": "socks5://127.0.0.1:9150"}
        output = requests.get("https://httpbin.org/get", proxies=proxies)
        print(2)
        print(json.loads(output.content))
    
    
    3 条回复    2023-11-17 14:44:46 +08:00
    xiaohundun
        1
    xiaohundun  
    OP
       163 天前
    求助求助😭
    hanssx
        2
    hanssx  
       163 天前
    pip install requests[socks] 试试
    xiaohundun
        3
    xiaohundun  
    OP
       163 天前
    @hanssx 有这个包,问题不在程序,是 tor 那里的出口节点访问目标站失败了,感觉是不是被 block 了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3346 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 11:18 · PVG 19:18 · LAX 04:18 · JFK 07:18
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.