Add modules/block_requests.py

This has become unnecessary, but it could be useful in the future
for other libraries.
This commit is contained in:
oobabooga 2023-06-18 16:31:14 -03:00
parent 687fd2604a
commit 09c781b16f
2 changed files with 22 additions and 14 deletions

19
modules/block_requests.py Normal file
View file

@ -0,0 +1,19 @@
import requests
from modules.logging_colors import logger
class RequestBlocker:
def __enter__(self):
self.original_get = requests.get
requests.get = my_get
def __exit__(self, exc_type, exc_value, traceback):
requests.get = self.original_get
def my_get(url, **kwargs):
logger.info('Unwanted HTTP request redirected to localhost :)')
kwargs.setdefault('allow_redirects', True)
return requests.api.request('get', 'http://127.0.0.1/', **kwargs)