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())
kecske
  • 649
  • 1
  • 8
  • 19
  • 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. – adamjford Jul 14 '11 at 17:31
  • 1
    I'm running into the same problem using the v3 api and basic authentication. – rubergly Aug 10 '11 at 21:30
  • 6
    It seems like an API problem, would be valid to post this as a bug for the github devs, just to make sure – Mario César Aug 12 '11 at 10:00
  • 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. – TomHarrigan Sep 12 '11 at 05:31
  • 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. – Malcolm Box Jan 12 '12 at 10:50

2 Answers2

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}
)
synthesizerpatel
  • 27,321
  • 5
  • 74
  • 91
  • 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. – kecske Jan 13 '12 at 23:54
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
Valentin Lorentz
  • 9,556
  • 6
  • 47
  • 69