General SOCKS server failure while using tor proxy

不问归期 提交于 2019-12-13 20:55:52

问题


I am proxying traffic over tor, so letter on when I need to call localhost port, it gives failure error.

def create_connection(self, address, timeout=None, source_address=None):
    sock = socks.socksocket()
    sock.connect(address)
    return sock

def getVideoTrend(self):

    socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
    socket.socket = socks.socksocket
    socket.create_connection = self.create_connection
    #some code
    Mongo.SaveEntity()

SaveEntity contains:

hostname = 'localhost'
port = 27017
self.client = MongoClient(hostname, port)

which gives

  File "radurl.py", line 110, in getVideoTrend
    MongoDbOpp().saveEntity(final_result)    
  File "/root/Documents/scraping/radurls/mongo_operation.py", line 14, in __init__
    self.client = MongoClient(hostname, port)
  File "/usr/local/lib/python2.7/dist-packages/pymongo/mongo_client.py", line 377, in __init__
    raise ConnectionFailure(str(e))
pymongo.errors.ConnectionFailure: 0x01: General SOCKS server failure

I understand the reason behind this error, that mongo attempts to connect to local control port, gets proxied through a tor exit node.

Is there any solution to this prob?

Or I can terminate tor session after before Mongo operation?


回答1:


Make mongo connection object before your code. Spent a day trying to figure this out. Then just changed the order of importing the mongo and tor files and it worked.



来源:https://stackoverflow.com/questions/31004104/general-socks-server-failure-while-using-tor-proxy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!