2 回答
TA贡献1803条经验 获得超6个赞
解决错误:InvalidSchema: Missing dependencies for SOCKS support
我通过在命令行中运行以下命令在 Windows 操作系统中重新启动 Tor 服务:
tor --service remove
然后
tor --service install -options ControlPort 9051
TA贡献1794条经验 获得超7个赞
您是否正在从 cli 运行 Tor 服务?
您的代理应如下所示:
session.proxies = {'http': 'socks5h://127.0.0.1:9050',
'https': 'socks5h://127.0.0.1:9050'}
此外,请求并非旨在以您描述的方式发出大量请求。我会建议使用以下设置,使用aiohttp,aiohttp_socks和asyncio。
import asyncio, aiohttp
from aiohttp_socks import SocksConnector
async def get_one(url, callback):
connector = SocksConnector.from_url('socks5://localhost:9050', rdns=True)
# rdns=True is important!
# 1) Can't connect to hidden services without it
# 2) You will make DNS lookup requests using your real IP, and not your Tor IP!
async with aiohttp.ClientSession(connector=connector) as session:
print(f'Starting {url}')
async with session.get(url) as res:
return await callback(res)
def get_all(urls, callback):
future = []
for url in urls:
task = asyncio.ensure_future(get_one(url, callback))
future.append(task)
return future
def test_callback(res):
print(res.status)
if __name__ == '__main__':
urls = [
'https://python.org',
'https://google.com',
#...
]
loop = asyncio.get_event_loop()
future = get_all(urls, test_callback)
loop.run_until_complete(asyncio.wait(future))
添加回答
举报