github issues api 401, why? (django)
Asked Answered
C

2

21

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.

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 = urllib2.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())
Cunctation answered 14/7, 2011 at 16:5 Comment(5)
I'm actually having a similar problem. I'm using Ruby, not Python, but the problem I'm having is I'm getting a 401 error back if I try to access the issues of a private repo which belongs to an organization to which I belong. I have full permissions on this repo.Celinecelinka
I'm running into the same problem using the v3 api and basic authentication.Durante
It seems like an API problem, would be valid to post this as a bug for the github devs, just to make sureMathilda
My company's intern was running into some problems with the API and github was great about helping him w/ the API as well as fixing an issue with the API itself.Noenoel
Looking at that code, I'm not convinced you're creating the OAuthed POST correctly. You need more than just the token - you should be signing a hash of the parameters as well? Why not try using an OAuth library to make the requests - much more likely to be successful.Dunsany
E
2

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}
)
Elsey answered 13/1, 2012 at 13:37 Comment(1)
Actually, 'title' and 'body' are some dummie text, to demonstrate the problem :), but if it works now for @Valentin Lorentz, they could have fixed the api problem.Cunctation
C
0

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
Christiansen answered 29/11, 2011 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.