'Monkey patching third-party library
I am using minio client and getting following error:
minio.error.InvalidEndpointError: InvalidEndpointError: message: Hostname does not meet URL standards.
This is caused by an incorrect regex in minio.helpers:281 function is_valid_endpoint(endpoint)
An upstream issue is open and I would like to learn how to monkey patch this with f = lambda: True when importing the Minio object.
from minio import Minio
# credentials['S3_ENDPOINT_URL'] = 'something.westeurope.azurecontainer.io'
minio_client = Minio(credentials['S3_ENDPOINT_URL'],
access_key=credentials['S3_ACCESS_KEY'],
secret_key=credentials['S3_SECRET_KEY'],
secure=USE_SSL)
Can someone please enlighten me how to monkey patch this? I've only used it for function definitions and not for classes before.
Solution 1:[1]
So for monkey patch you can simply replace the function
First define a function that always returns true:
def is_valid_replacer(endpoint):
return True
Then Just replace the function
import minio
minio.helpers.is_valid_endpoint = is_valid_replacer
#### Your code here ####
If I understood you this should work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Luiz Fernando Lobo |
