2017-04-19 56 views
0

我正在處理一個python腳本來關閉一個pull請求,但我似乎無法正確格式化請求......有人能告訴我我在做什麼錯嗎?python github清理

for repo in g.get_user().get_repos(): 
print (repo.full_name) 
json_pulls = requests.get(base_url + repo.full_name + '/pulls?state=open+updated>=' + str(cutoff_date.date())+ '&sort=created&order=asc') 
if (json_pulls.ok): 
    for item in json_pulls.json(): 
     print('Name: ' + item['title']) 
     print('Number: ' + str(item['number'])) 
     print('State: ' + item['state']) 
     print('Last Updated: ' + str(item['updated_at'])) 
     print('Last Merged : ' + str(item['merged_at'])) 
     print (' ') 
     pull_num = str(item['number']) 
     merged_date = item['merged_at'] 
     if isinstance(merged_date, datetime) and (merged_date < cutoff_date): 
      print('Pull Request recently merged.... Skipping... ') 
      print(' ') 
      print(' ') 
     else: 
      print('Action: Close pull request: ' + pull_num) 
      print(' ') 
      print(' ') 
      head = {"Authorization": "Token token=" + OAUTH_KEY} 
      payload = { 
       "state": "closed" 
      } 
      r = requests.patch(base_url + repo.full_name + '/pulls/' + pull_num, head, json=payload) 
      print(r.json()) 

輸出:

Name: Issue01 
Number: 1 
State: open 
Last Updated: 2017-04-18T14:21:31Z 
Last Merged : None 

Action: Close pull request: 1 


{'message': 'Not Found', 'documentation_url': 'https://developer.github.com/v3/pulls/#update-a-pull-request'} 

感謝您的幫助!

回答

0

它看起來像你的Authorization字符串是不正確,應該是:

head = {"Authorization": "token " + OAUTH_KEY} 

(從the API docs