为什么在子进程中运行时,git 出现 “getaddrinfo() 线程启动失败”?

huangapple go评论64阅读模式
英文:

Why does git fail with "getaddrinfo() thread failed to start" when in a subprocess?

问题

我的Python代码调用subprocess.Popen()并运行以下命令:

git clone -b master --single-branch https://github.com/kivy/python-for-android.git python-for-android

我从Windows 11的PyCharm终端中运行我的Python代码。

它无法运行getaddrinfo()

Cloning into 'python-for-android'...
fatal: unable to access 'https://github.com/kivy/python-for-android.git/': getaddrinfo() thread failed to start

我在同一个终端中直接运行相同的命令,它运行得很完美。

嗯...听起来好像无法获取网络访问权限...与这个相关问题的答案都建议检查防火墙。

我只有Microsoft Defender防火墙,我尝试关闭了所有的域网络、专用网络和公共网络防火墙(我的路由器仍在保护我)。但没有任何改变。

我原本认为防火墙,即使打开了,也应该关注git.exe(我已确认它们找到了相同的exe文件),并且不会在一个上触发而在另一个上不触发。

下一步应该在哪里查找?是否有任何线索可以说明在Python子进程中运行时阻止git访问网络的原因?

英文:

My Python code calls subprocess.Popen() with a command:

 git clone -b master --single-branch https://github.com/kivy/python-for-android.git python-for-android

I call my Python code from the command line Terminal within PyCharm, on Windows 11.

It fails to run getaddrinfo():

Cloning into 'python-for-android'...
fatal: unable to access 'https://github.com/kivy/python-for-android.git/': getaddrinfo() thread failed to start

I run the exact same command directly in the same terminal, and it runs perfectly.

Hmmm... That sounds like it can't get network access... and the answers to this related question all agree to check the firewall.

I only have Microsoft Defender Firewall, and I tried turning off all of the Domain network, Private Network and Public Network firewalls. (My router is still protecting me.) It makes no difference.

I would have thought the firewall, even if it were on, would be paying attention to git.exe (I have confirmed they are finding the same exe.) and wouldn't trigger on one and not the other.

Where should I look next? Any clues what might be blocking git from accessing the network when running in a Python subprocess?

答案1

得分: 1

子进程中没有包含环境变量 SystemRoot(通常指向 C:\WINDOWS)。

如果您在没有设置该环境变量的情况下运行 git,它会产生相同的错误。

英文:

The subprocess did not contain the environment variable SystemRoot (which typically points to C:\WINDOWS).

If you run git without that environment variable set, it gives that same error.

huangapple
  • 本文由 发表于 2023年7月10日 22:47:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654896.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定