bravado
bravado copied to clipboard
How to visit API url by a proxy?
I am a newbee to bravado and I try to visit API url by a proxy, just like
client = SwaggerClient.from_url( 'http://petstore.swagger.io/v2/swagger.json', http_client=http_client, proxy = {'https':'socks5h://127.0.0.1:1080'}, )
But I don't know where to put my proxy settings even after I checked #4946.
I'm doing it like this:
class ExtendedRequestsClient(RequestsClient):
def __init__(self):
super(ExtendedRequestsClient, self).__init__()
def set_proxies(self, proxies:dict):
self.session.trust_env = False
self.session.proxies.update(proxies)
def create_api(url, proxies: dict = {}):
http_client = ExtendedRequestsClient()
if proxies:
http_client.set_proxies(proxies)
specs = load_url(url, http_client)
api = SwaggerClient.from_spec(specs, http_client=http_client, origin_url=url, config=HTTP_CLIENT_CONFIG)
return api, http_client