-
-
Notifications
You must be signed in to change notification settings - Fork 954
-
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
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
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.
Beta Was this translation helpful? Give feedback.