python-github3 icon indicating copy to clipboard operation
python-github3 copied to clipboard

How to set proxies?

Open YMMS opened this issue 8 years ago • 1 comments

I wrote my test code as follows:

from pygithub3 import Github
proxies = {"http": "http://<ip>:<port>", "https": "http://<ip>:<port>", }
gh = Github(login=<userID>, password=<userPWD>, token=<OAUTH-TOKEN>, proxies = proxies)
use = gh.users.get(<userID>)

Which raise:

  File "/my/path/to/test/code/v1.py", line 10, in <module>
    octocat = gh.users.get()
  File "/usr/local/lib/python2.7/dist-packages/pygithub3/services/users/__init__.py", line 36, in get
    return self._get(request)
  File "/usr/local/lib/python2.7/dist-packages/pygithub3/services/base.py", line 143, in _get
    response = self._client.get(request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pygithub3/core/client.py", line 84, in get
    response = self.request('get', request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pygithub3/core/client.py", line 71, in wrapper
    return func(self, verb, request, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/pygithub3/core/client.py", line 77, in request
    response = self.requester.request(verb, request, **kwargs)
  File "/my/path/anaconda2/lib/python2.7/site-packages/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/my/path/anaconda2/lib/python2.7/site-packages/requests/sessions.py", line 585, in send
    r = adapter.send(request, **kwargs)
  File "/my/path/anaconda2/lib/python2.7/site-packages/requests/adapters.py", line 467, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='api.github.com', port=443): Max retries exceeded with url: /user?access_token=<OAUTH-TOKEN>&per_page=100 (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f4cbf2fb890>: Failed to establish a new connection: [Errno -5] No address associated with hostname',))

I tried link https//api.github.com/user?access_token=<OAUTH-TOKEN>&per_page=100 with requests like:

import requests   
proxies = { "http": "http://<IP>:<PORT>", "https": "http:<IP>:<PORT>", }   
a = requests.get("https://api.github.com/user?access_token=<AOTH-TOKEN>&per_page=100", proxies=proxies)  
for key, value in a.__dict__.items():
    print key, ":", value

It works.

When I debug the first section of code described as above, I found an problem:

When run the gh = Github(login=<userID>, password=<userPWD>, token=<OAUTH-TOKEN>, proxies = proxies), gh._users._client.config contains the params what I assigned. But when run the gh.users.get() the gh.users._client.config={}.

Could anyone tell me how to set proxies?

YMMS avatar Feb 13 '17 12:02 YMMS

Unfortunately it does not allow passing proxy info as parameter, but takes from environment variable "http_proxy"

krishvarag avatar Jan 03 '18 20:01 krishvarag