github 出现 api 401 问题,为什么? (姜戈)

发布于 2024-11-19 23:30:54 字数 1606 浏览 4 评论 0原文

我正在尝试将 github issues api 集成到项目中。我认为我遵循了 oauth 规则,以及 http://develop.github.com 上需要和提到的所有内容/p/issues.html, 但它似乎不起作用。我没有收到详细的错误消息,只有 401。

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())

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())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

寻找我们的幸福 2024-11-26 23:30:54

问题可能是..

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

您指定标题参数具有“title”的字面值,与“body”相同。

你可能想要这个吗? ..

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

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}
)
简单气质女生网名 2024-11-26 23:30:54

我不知道这是否正是您所需要的,但这是我在我的项目之一中用于打开问题的代码:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文