Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

How to use a proxy for fetch and pull? #1457

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

Closed
Mips128 opened this issue Jun 17, 2022 · 0 comments
Closed

How to use a proxy for fetch and pull? #1457

Mips128 opened this issue Jun 17, 2022 · 0 comments

Comments

@Mips128
Copy link

Mips128 commented Jun 17, 2022

Hi,

I just have a quick question. In a program, I utilize gitpython to update some scripts. I want to support proxies for the pull and fetch operations. Therefore, I tried various ways to set the http proxy for python. Cloning the repository via a proxy is not needed, because the repo is copied onto the machine during the installation of the program.
First attempt:

uri_proxy = 'http://34.145.226.144:8080'

git_o = git.cmd.Git()
repo = git.Repo(".")
repo.remotes.origin.set_url(uri_remote_git)
with git_o.custom_environment(HTTP_PROXY= uri_proxy), repo.git.custom_environment(HTTP_PROXY= uri_proxy):
	repo.remotes.origin.pull()
	repo.remotes.origin.fetch()

The operation completes successfully, but the proxy is not used. Instead gitpython directly communicates with the git server specified in uri_remote_git.

Next try:

env=dict(HTTP_PROXY=uri_proxy)
repo.remotes.origin.pull(env=env)
repo.remotes.origin.fetch(env=env)

Same result as before.
Running:

repo.remotes.origin.pull(config="http.proxy='" + uri_proxy + "'")

Results in the following error:

  File "<stdin>", line 1, in <module>
  File "C:\Users\dennis\AppData\Roaming\Python\Python39\site-packages\git\remote.py", line 910, in pull
    res = self._get_fetch_info_from_stderr(proc, progress,
  File "C:\Users\dennis\AppData\Roaming\Python\Python39\site-packages\git\remote.py", line 750, in _get_fetch_info_from_stderr
    proc.wait(stderr=stderr_text)
  File "C:\Users\dennis\AppData\Roaming\Python\Python39\site-packages\git\cmd.py", line 502, in wait
    raise GitCommandError(remove_password_if_present(self.args), status, errstr)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(129)
  cmdline: git pull -v --config=http.proxy='http://34.145.226.144:8080' origin
  stderr: 'error: unknown option `config=http.proxy='http://34.145.226.144:8080'''

Setting the environment variable http_proxy has no effect either – the proxy is ignored

os.environ['HTTP_PROXY'] = uri_proxy 
os.environ['http_proxy'] = uri_proxy 
repo.remotes.origin.pull()
repo.remotes.origin.fetch()

Can you help me how to achieve this?

Thanks!

Dennis

@gitpython-developers gitpython-developers locked and limited conversation to collaborators Jun 18, 2022
@Byron Byron converted this issue into discussion #1458 Jun 18, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Development

No branches or pull requests

1 participant