General SOCKS server failure while using tor proxy

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, "", 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 "", line 110, in getVideoTrend MongoDbOpp().saveEntity(final_result) File "/root/Documents/scraping/radurls/", line 14, in __init__ self.client = MongoClient(hostname, port) File "/usr/local/lib/python2.7/dist-packages/pymongo/", 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?

Category:python Views:187 Time:2019-01-10

Related post

Copyright (C), All Rights Reserved.

processed in 0.078 (s). 11 q(s)