Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to visit API url by a proxy? #361

Open
yiyusheng opened this issue May 16, 2018 · 1 comment
Open

How to visit API url by a proxy? #361

yiyusheng opened this issue May 16, 2018 · 1 comment

Comments

@yiyusheng
Copy link

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.

@Vadiml1024
Copy link

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants