开发者

github issues api 401, why? (django)

I'm trying to integrate github issues api into a project. I think I'm following the rules of oauth, and everything that is needed and mentioned on http://develop.github.com/p/issues.html, but it doesn't seem to work. I don't get detailed error message, just a 401.

  • i registered an oauth app at github(api v2), and provided the callback url.
  • i construct the auth url: https://github.com/login/oauth/authorize?client_id=...&redirect_uri=http://.../no_port/
  • They post the code for me(request token), i exchange it ho access token, it works fine. The problems:
  • I can watch my own issues on my own repos, but if i'm just a collaborator, it's 401(unauthorized)
  • There's no way to create a new issue, even on my own repo: POST: http://github.com/api/v2/json/issues/open/:user/:repo PARAMS: body=&login=&token=6&title=

actual implementatios with django, python:

url = 'https://github.com/login/oauth/access_token?client_id=%(client_id)s&redirect_uri=%(redirect_uri)s&client_secret=%(client_secret)s&code=%(code)s' % locals()        
req = urllib2.Request(url)
response = urllib开发者_运维百科2.urlopen(req).read()
access_token = re.search(r'access_token=(\w+)', response).group(1)
url = 'http://github.com/api/v2/json/issues/open/%(user)s/%(repo)s' % locals()
params = urllib.urlencode({'login': user, 'token': access_token, 'title': 'title', 'body': 'body'})
req = urllib2.Request(url, params)
try:
    response = urllib2.urlopen(req)
except HTTPError, e:
    return HttpResponse('[*] Its a fckin %d' % e.code)
except URLError, e:
    return HttpResponse('[*] %s\n' % repr(e.reason))
else:
    resp = json.loads(response.read())


Could the problem be..

params = urllib.urlencode(
    {'login': user, 'token': access_token, 'title': 'title', 'body': 'body'}
)

You specify that the title param has the literal value of 'title', same with 'body'.

Do you possibly want this instead? ..

params = urllib.urlencode(
    {'login': user, 'token': access_token, 'title': title, 'body': body}
)


I don't know if it is exactly what you need, but this is the code I use in one of my project to open issues:

def issue(self, channel, network, nick, user, title, repoName):
    body = 'Issue sent from %s at %s by %s (registered as %s)' % \
            (channel, network, nick, user.name)
    login = self.registryValue('login')
    token = self.registryValue('token')
    data='title=%s&body=%s&login=%s&token=%s' % (title, body, login, token)
    url = 'http://github.com/api/v2/json/issues/open/' + repoName
    response = json.loads(urllib.urlopen(url, data=data).read())
    id = response['issue']['number']
    return id
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜