PyMongo proxy - http/socks proxy support with python-socks.
This repo forked from Pymongo official repo for http/socks proxy support with the help of python-socks. DNS resolving done by pymongo itself. Connection done by python-socks. For more information please refer to Pymongo and about proxies refer to python-socks.
If you installed pymongo before you need to remove it first:
pip uninstall pymongo
Install it with git:
pip install git+https://github.com/benjamintenny/mongo-python-driver-proxy
You can also download the project source and then install it with pip:
pip install .
Here's a basic example about using pymongo with proxies:
import os
import pymongo
# Set socks5 proxy
os.environ["MONGO_PROXY"] = "socks5://127.0.0.1:1080"
# Connect to db as normal
client = pymongo.MongoClient("your-mongodb-url")
db = client.test
print(db.name)
Also you can:
Socks5 with authentication:
os.environ["MONGO_PROXY"] = "socks5://username:[email protected]:1080"
HTTP proxy with authentication:
os.environ["MONGO_PROXY"] = "http://username:[email protected]:8080"
Socks4 proxy:
os.environ["MONGO_PROXY"] = "socks4://127.0.0.1:1080"