"from git import Repo"\n\n# \u5730\u65b9\u4ed3\u5e93\u7684\u8def\u5f84\nrepo_path = '/home/tumispider'\n\n# \u521d\u59cb\u5316\u4ed3\u5e93\u5bf9\u8c61\nrepo = Repo(repo_path)\n\n# \u5207\u6362\u5230dev\u5206\u652f\nrepo.git.checkout('dev')\n\n# \u6295\u53d6\u6700\u65b0\u4ee3\u7801\nresult = repo.git.pull()\nprint(result.stdout)\nTraceback (most recent call last):\n File "/home/git_pull.py", line 14, in \n print(result.stdout)\nAttributeError: 'str' object has no attribute 'stdout'\n\n\u5f02\u8bef\u00a0:\u00a0\u5185\u5bb9\u00a0:\u00a0AttributeError: 'str' object has no attribute 'stdout'\n\n\u8fd9\u4e2a\u9519\u8bef\u662f\u56e0\u4e3aresult\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5bf9\u8c61\uff0c\u800c\u5b57\u7b26\u4e32\u5bf9\u8c61\u6ca1\u6709stdout\u5c5e\u6027\u3002\u5728git.pull()\u65b9\u6cd5\u4e2d\uff0c\u8fd4\u56de\u7684\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5bf9\u8c61\uff0c\u5305\u542b\u4e86\u6295\u53d6\u7684\u7ed3\u679c\u4fe1\u606f\u3002\n\n\u8981\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u76f4\u63a5\u6253\u5370result\uff0c\u6216\u8005\u4f7f\u7528subprocess\u6a21\u5757\u6765\u6267\u884cgit pull\u547d\u4ee4\u5e76\u83b7\u53d6\u7ed3\u679c\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528subprocess\u6a21\u5757\u7684\u793a\u4f8b\u4ee3\u7801\uff1a\n\npython\nimport subprocess\n\n# \u6267\u884cgit pull\u547d\u4ee4\nresult = subprocess.run(['git', '-C', repo_path, 'pull'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)\n\n# \u8f93\u51fa\u7ed3\u679c\nprint(result.stdout)\n\n\n\u8fd9\u6837\u5c31\u53ef\u4ee5\u6b63\u786e\u83b7\u53d6\u5e76\u6253\u5370\u51fagit pull\u7684\u7ed3\u679c\u4fe1\u606f\u3002

Python Git Pull 错误: AttributeError: 'str' object has no attribute 'stdout' 的解决方法

原文地址: https://www.cveoy.top/t/topic/pWEN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录