问题
when I try to follow the tutorial (https://stem.torproject.org/tutorials/to_russia_with_love.html) about how to start up Tor I keep getting stuck at 45% and sometimes at 50%. I am using windows 8, python 3.4 and the LiClipse ide.
[1mStarting Tor: [0m [34mApr 26 12:47:21.000 [notice] Bootstrapped 0%: Starting[0m [34mApr 26 12:47:21.000 [notice] Bootstrapped 45%: Asking for relay descriptors[0m [34mApr 26 13:04:00.000 [notice] Bootstrapped 50%: Loading relay descriptors[0m
The script looks like this, the change I have made myself here is to use requests
library instead of urllib
to rquest data from a source but I'm not getting to that part of the code here anyway. This is basicly a copy of the code at the tutorial page using SocksiPy.
TorConnector.py:
from io import StringIO
import socket
import requests
import socks # SocksiPy module
import stem.process
from stem.util import term
SOCKS_PORT = 7000
# Set socks proxy and wrap the urllib module
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', SOCKS_PORT)
socket.socket = socks.socksocket
# Perform DNS resolution through the socket
def getaddrinfo(*args):
return [(socket.AF_INET, socket.SOCK_STREAM, 6, '', (args[0], args[1]))]
socket.getaddrinfo = getaddrinfo
def query(url):
"""
Uses requests to fetch a site using SocksiPy for Tor over the SOCKS_PORT.
"""
try:
result = requests.get(url)
return result
except:
return "Unable to reach %s" % url
# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running.
def print_bootstrap_lines(line):
if "Bootstrapped " in line:
print(term.format(line, term.Color.BLUE))
print(term.format("Starting Tor:\n", term.Attr.BOLD))
tor_process = stem.process.launch_tor_with_config(
config = {
'SocksPort': str(SOCKS_PORT),
'ExitNodes': '{ru}',
},
init_msg_handler = print_bootstrap_lines,
)
print(term.format("\nChecking our endpoint:\n", term.Attr.BOLD))
print(term.format(query("https://www.atagar.com/echo.php"), term.Color.BLUE))
tor_process.kill() # stops tor
I have also tried moving the TorConnector.py script file in to the C:\Python34\Lib\site-packages
folder and run it from a command prompt with python TorConnector.py
but same thing happens, I am still stuck on 45%.
Also, if I end Tor.exe process when its stuck at 45% it tells me this:
Traceback (most recent call last): File "C:\Users\gatsu\My Documents\LiClipse Workspace\TorCommunicator\TorConnector.py", line 53, in init_msg_handler = print_bootstrap_lines, File "C:\Python34\lib\site-packages\stem\process.py", line 246, in launch_tor_with_config return launch_tor(tor_cmd, args, torrc_path, completion_percent, init_msg_handler, timeout, take_ownership) File "C:\Python34\lib\site-packages\stem\process.py", line 136, in launch_tor raise OSError('Process terminated: %s' % last_problem) OSError: Process terminated: Failed to open GEOIP file C:\Users\gatsu\AppData\Roaming\tor\geoip6. We've been configured to use (or avoid) nodes in certain countries, and we need GEOIP information to figure out which ones they are.
I hope it helps to figure out why this is making me get stuck.
I do not even have this file: C:\Users\gatsu\AppData\Roaming\tor\geoip6
回答1:
I found the geoip
and geoip6
files in the tor browser folder (D:\Program\Tor Browser\Browser\TorBrowser\Data\Tor) and copied them to C:\Users\gatsu\AppData\Roaming\tor which then made me reach 100%.
[1mStarting Tor: [0m [34mMay 01 23:28:53.000 [notice] Bootstrapped 0%: Starting[0m [34mMay 01 23:28:53.000 [notice] Bootstrapped 80%: Connecting to the Tor network[0m [34mMay 01 23:28:54.000 [notice] Bootstrapped 85%: Finishing handshake with first hop[0m [34mMay 01 23:28:54.000 [notice] Bootstrapped 90%: Establishing a Tor circuit[0m [34mMay 01 23:28:55.000 [notice] Bootstrapped 100%: Done[0m [1m Checking our endpoint: [0m [34mUnable to reach https://www.atagar.com/echo.php[0m
回答2:
Related to the answer provided by @Alter. In a MacOs Sierra, a tor_process config that works (solving this issue) is
tor_process = stem.process.launch_tor_with_config(
tor_cmd = '/Applications/TorBrowser.app/Contents/MacOS/Tor/tor.real',
config = {
'SocksPort': str(SOCKS_PORT),
'ExitNodes': '{ru}',
'GeoIPFile': r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip',
'GeoIPv6File' : r'/Applications/TorBrowser.app/Contents/Resources/TorBrowser/Tor/geoip6'
},
init_msg_handler = print_bootstrap_lines,
)
回答3:
Alternatively, you can specify where the geoip and geoipv6 currently are by passing them into your config. See the TOR manual for a complete list of config options.
tor_process = stem.process.launch_tor_with_config(
config = {
'SocksPort': str(SOCKS_PORT),
'ExitNodes': '{ru}',
'GeoIPFile': r'C:\Program Files (x86)\tor-win32-0.2.8.9\Data\Tor\geoip',
'GeoIPv6File' : r'C:\Program Files (x86)\tor-win32-0.2.8.9\Data\Tor\geoip6'
},
init_msg_handler = print_bootstrap_lines,
)
as a side note, if you had this error. You need to kill the TOR process that was stuck at 45% before you run another (in windows, go into task manager and find/kill 'tor)'
来源:https://stackoverflow.com/questions/29876778/tor-tutorial-speaking-to-russia-stuck-at-45-50