I want to make an anonymous web request using python 3 with help of Tor, and I'm following this tutorial: https://computerscienceandfangs.blogspot.com/2018/04/setting-up-tor-for-windows-10-python-3.html.
So far I'm just testing the first part of the tutorial code (below):
import requests
def get_tor_session():
session = requests.session()
# Tor uses the 9050 port as the default socks port
session.proxies = {'http': 'socks5://127.0.0.1:9050',
'https': 'socks5://127.0.0.1:9050'}
return session
# Make a request through the Tor connection
# IP visible through Tor
session = get_tor_session()
print(session.get("http://httpbin.org/ip").text)
# Above should print an IP different than your public IP
# Following prints your normal public IP
print(requests.get("http://httpbin.org/ip").text)
So when I execute the code: print(session.get("http://httpbin.org/ip").text)
, it should show me a different IP address to mine. However instead I get the error:
File "C:\Program Files\Anaconda3\lib\site-packages\requests\adapters.py", line 43, in SOCKSProxyManager
try:
InvalidSchema: Missing dependencies for SOCKS support.
I've installed the packages below as per the tutorial:
1)pip install requests -- upgrade
2)pip install requests[socks]
3)pip install stem
I'm using Windows 7 (64-bit). Spyder for Python IDE. Python version 3.5.
Second question, which is more general. I'm looking to make requests on a bigger scale as part of a project for a web-scraper. Is the approach above, using the tutorial I referenced, still a good approach (i.e. coding things manually using Python), to ensure you don't get banned/black-listed? Or Are there services out there more advanced that can do Anonymous IP request, IP rotating and request throttling all for you, without you having to code your own software and configure manually, and with unlimited number of requests?
Many thanks in advance.
To resolve the error: InvalidSchema: Missing dependencies for SOCKS support
I had restart Tor service in Windows OS, by running the following in command line:
tor --service remove
then
tor --service install -options ControlPort 9051