使用Python脚本从组织/用户获取所有私有存储库

时间:2020-04-03 05:17:37

标签: python api github

我在Mac上,正在尝试运行python脚本来从我的组织/员工那里获取所有私人仓库。这是我到目前为止的内容:

import github3

gh = github3.login("username", "personal_access_taken")
org = gh.organization("org_name")
repos = list(org.iter_repos(type="private"))

print(repos)

仅供参考,我是python和API的新手。几个小时前才刚开始,所以我是一个新手。我跑了回去:

Traceback (most recent call last): File "repo.py", line 4, in <module> org = gh.organization("org_name") File "/Users/user/Library/Python/2.7/lib/python/site-packages/github3/github.py", line 1566, in organization json = self._json(self._get(url), 200) File "/Users/user/Library/Python/2.7/lib/python/site-packages/github3/models.py", line 156, in _json raise exceptions.error_for(response) github3.exceptions.NotFoundError: 404 Not Found

我应该对脚本进行哪些更改才能使其正常运行?另外,如果我需要更换员工,我可以将org = gh.organization("org_name")替换为user = gh.user("employee_name)吗?

1 个答案:

答案 0 :(得分:0)

我尝试了您的代码,它对我有用。

确保您输入了正确的组织名称,并且您的用户有权访问此组织:

#include "SevSeg.h"
SevSeg sevseg; 


const int  BUTTON = 1;    
int buttonState = 0;          
int lastButtonState = LOW;   

void setup(){
  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};

  bool resistorsOnSegments = true; 
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_ANODE; 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, 
resistorsOnSegments);
  sevseg.setBrightness(150);

  pinMode(BUTTON, OUTPUT);
  Serial.begin(9600);
  lastButtonState = LOW;
}

void loop(){
  sevseg.setNumber();
  sevseg.refreshDisplay();
  if (digitalRead (BUTTON) == HIGH)
  {
    rand() % 20 + 1;
  }
}

您还应该将已弃用的org = gh.organization("org_name") 替换为repositories()方法:

iter_repos()