Created
January 5, 2022 12:18
-
-
Save rcbadiale/6d785b60314d6531eaf417e71e888364 to your computer and use it in GitHub Desktop.
A function to patch the urllib3 / requests to print and/or change the hosts as needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from urllib3.util import connection | |
| def patch_requests_connector(): | |
| _create_connection = connection.create_connection | |
| def patched_create_connection(address, *args, **kwargs): | |
| """ | |
| Patches the create_connection in order to print the hosts. | |
| This is useful in cases of the requests being redirected to | |
| unavailable hostnames, with this you can check which host:port | |
| is being used in every request made. | |
| If needed this patch can be modified to resolve the names into | |
| different routes. | |
| """ | |
| host, port = address | |
| print(address, host, port) | |
| return _create_connection((host, port), *args, **kwargs) | |
| connection.create_connection = patched_create_connection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment