Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Unanswered
Mips128 asked this question in Q&A
Discussion options

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

You must be logged in to vote

Replies: 1 comment

Comment options

It doesn't look like the HTTP_PROXY environment variable is used at all. Instead it needs to be configured like you tried, or like described in this gist.

repo.remotes.origin.pull(config="http.proxy='" + uri_proxy + "'") doesn't work because it adds the configuration information to the wrong spot in the command-line, and there is no way to change that.

Instead, one could run repo.git.config(...) and set the configuration of the repository itself, it will be picked up from there.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1457 on June 18, 2022 00:51.

AltStyle によって変換されたページ (->オリジナル) /