我正在尝试使用 github oauth。我正在使用 urllib 和 urllib2 并具有以下代码:
def github_login(request):
post_data = [('client_id','****'),('redirect_uri','http://localhost:8000/callback')]
result = urllib2.urlopen('https://github.com/login/oauth/authorize', urllib.urlencode(post_data))
content = result.read()
在发送查询后我有 httperror 403。我已经在 settings.py 中配置了 allowed_hosts
请您参考如下方法:
从我的经验来看,我知道使用 urllib 很难,我建议使用 requests http://requests.readthedocs.org/en/latest/
您可以轻松发送:
r = requests.get('https://api.github.com/user', auth=('user', 'pass'))
