Requests supports HTTP proxies, but not SOCKS proxies, which is what Tor provides you.
You can either get a patched version of requests: How to make python Requests work via socks proxy
Or install Polipo and use it as another proxy to "transform" Tor's SOCKS5 proxy into a HTTP/HTTPS proxy. Here's my config file:
proxyName = "localhost"
proxyAddress = "127.0.0.1"
proxyPort = 8118
allowedClients = 127.0.0.1
allowedPorts = 1-65535
cacheIsShared = false
chunkHighMark = 67108864
socksParentProxy = "localhost:9050"
socksProxyType = socks5
diskCacheRoot = ""
localDocumentRoot = ""
disableLocalInterface = true
disableConfiguration = true
disableVia = true
dnsUseGethostbyname = yes
maxConnectionAge = 5m
maxConnectionRequests = 120
serverMaxSlots = 8
serverSlots = 2
tunnelAllowedPorts = 1-65535
Now, you can just use the proxies with requests:
proxies = {
'http': 'localhost:8118',
'https': 'localhost:8118'
}
requests.get('http://something.onion/', proxies=proxies)