首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Tor和Meteor DDP

使用Tor和Meteor DDP
EN

Stack Overflow用户
提问于 2015-05-10 11:39:42
回答 1查看 365关注 0票数 0

我正在尝试使用一个流星ddp客户端来使用我的python脚本中的一个流星应用程序中的数据。它是一个使用Tor代理API的脚本,名为stem。如果单独运行的话,我的tor通信器就是这样工作的:

Tor通信器(取自tor教程页,但有小改动):

代码语言:javascript
复制
import socket
import socks
import stem.process
import requests
from stem.util import term
from requestData import requestData

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(itemId):
    """
    Uses requests to fetch a site using SocksiPy for Tor over the SOCKS_PORT.
    """

    try:
        return requestData(itemId)
    except:
        return "Unable to get data"

# 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(line)


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,
)

tor_process.kill()  # stops tor

上面的脚本是从这个脚本运行的:

代码语言:javascript
复制
import Communicator
from MeteorClient import MeteorClient

client = MeteorClient('ws://127.0.0.1:3000/websocket')
client.connect()

def subscription_callback(error):
    if error:
        print(error)

client.subscribe('accounts', callback=subscription_callback)

all_posts = client.find('accounts')
print(all_posts)

Communicator.query("190aqe41vbewh7367f2hf27521")

但是它给了我这个结果:

代码语言:javascript
复制
[1mStarting Tor:
[0m
May 10 13:21:45.000 [notice] Bootstrapped 0%: Starting
May 10 13:21:45.000 [notice] Bootstrapped 80%: Connecting to the Tor network
May 10 13:21:46.000 [notice] Bootstrapped 85%: Finishing handshake with first hop
May 10 13:21:46.000 [notice] Bootstrapped 90%: Establishing a Tor circuit
May 10 13:21:47.000 [notice] Bootstrapped 100%: Done
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\socks.py", line 663, in connect
    _BaseSocket.connect(self, proxy_addr)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\gatsu\My Documents\LiClipse Workspace\TorCommunicator\MeteorDDP.py", line 5, in <module>
    client.connect()
  File "C:\Python34\lib\site-packages\python_meteor-0.1.6-py3.4.egg\MeteorClient.py", line 55, in connect
  File "C:\Python34\lib\site-packages\python_ddp-0.1.5-py3.4.egg\DDPClient.py", line 119, in connect
  File "C:\Python34\lib\site-packages\ws4py-0.3.4-py3.4.egg\ws4py\client\__init__.py", line 209, in connect
  File "C:\Python34\lib\site-packages\socks.py", line 674, in connect
    raise ProxyConnectionError(msg, error)
socks.ProxyConnectionError: Error connecting to SOCKS5 proxy 127.0.0.1:7000: [WinError 10061] No connection could be made because the target machine actively refused it
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-14 14:55:08

在完成Meteor操作之后,在调用Communicator中的方法之前,我通过导入Communicator来解决这个问题。

代码语言:javascript
复制
from MeteorClient import MeteorClient

client = MeteorClient('ws://127.0.0.1:3000/websocket')
client.connect()

def subscription_callback(error):
    if error:
        print(error)

client.subscribe('accounts', callback=subscription_callback)

all_posts = client.find('accounts')
print(all_posts)

import Communicator
Communicator.query("190aqe41vbewh7367f2hf27521")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30150940

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档