gpt4 book ai didi

python - Windows Live 登录 API SSL 问题 - Python

转载 作者:太空宇宙 更新时间:2023-11-03 13:42:51 25 4
gpt4 key购买 nike

我正在编写一个程序,将多个 Windows Live 联系人邀请到一个 Web 应用程序中,所有这些都在 Django 1.4 中。我遇到了以下问题。

我可以使用这段代码通过 Windows Live REST API 使用他的帐户凭据在 Windows Live 中登录用户

def hotmail(request):
auth_params = {
'client_id': settings.HOTMAIL_KEY,
'scope': 'wl.basic',
'response_type': 'code',
'redirect_uri': 'http://my_testing_comain/hotmail/process'
}
auth_url = settings.HOTMAIL_AUTH_URL % urllib.urlencode(auth_params)
return HttpResponseRedirect(auth_url)

然后,我收到一个授权码,我用它交换访问 token (根据 OAuth 协议(protocol))这是我用来处理 Windows Live 响应的代码片段:

def hotmail_process(request):
if request.method == 'GET':
parameters = {
'code': request.GET['code'],
'grant_type': 'authorization_code',
'redirect_uri': 'http://my_testing_url/hotmail/process',
'client_id': settings.HOTMAIL_KEY,
'client_secret': settings.HOTMAIL_SECRET,
}
response = urllib2.urlopen(settings.HOTMAIL_AUTH_URL % urllib.urlencode(parameters)).read()
response = simplejson.loads(response)
consumer = oauth.Consumer(settings.HOTMAIL_KEY, settings.HOTMAIL_SECRET)
client = oauth.Client(consumer)
contacts = client.request(settings.HOTMAIL_USER_FRIENDS_URI % response['access_token'])
return HttpResponse(simplejson.loads(contacts))
return HttpResponse('Invalid request')

但是我得到以下错误:

SSLHandshakeError at /hotmail/process/
[Errno 1] _ssl.c:499: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
Request Method: GET
Request URL: http://my_testing_url/hotmail/process/?code=5330307c-664c-4d5b-27b3-a19a97bc8546
Django Version: 1.4
Exception Type: SSLHandshakeError
Exception Value:
[Errno 1] _ssl.c:499: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

and the following traceback:


Environment:


Request Method: GET
Request URL: http://my_testing_url/hotmail/process/?code=5330307c-664c-4d5b-27b3-a19a97bc8546

Django Version: 1.4
Python Version: 2.7.1
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'contacts')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/home/user/virtenvs/israel/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/user/virtenvs/israel/networks/contacts/views.py" in hotmail_process
26. contacts = client.request(settings.HOTMAIL_USER_FRIENDS_URI % response['access_token'])
File "/home/user/virtenvs/israel/lib/python2.7/site-packages/oauth2/__init__.py" in request
682. connection_type=connection_type)
File "/home/user/virtenvs/israel/lib/python2.7/site-packages/httplib2/__init__.py" in request
1544. (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/home/user/virtenvs/israel/lib/python2.7/site-packages/httplib2/__init__.py" in _request
1294. (response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/home/user/virtenvs/israel/lib/python2.7/site-packages/httplib2/__init__.py" in _conn_request
1230. conn.connect()
File "/home/user/virtenvs/israel/lib/python2.7/site-packages/httplib2/__init__.py" in connect
1005. raise SSLHandshakeError(e)

Exception Type: SSLHandshakeError at /hotmail/process/
Exception Value: [Errno 1] _ssl.c:499: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

问题是,如果我删除为此执行 client.request() 的行:

return HttpResponseRedirect(settings.HOTMAIL_USER_FRIENDS_URI % response['access_token'])

我在浏览器中获取 json 格式的联系人

所以,显然,我的 python oauth2 库缺少一些证书(或者这就是我的想法),所以我尝试了这个 Python - SSL Issue with Oauth2没有结果。在发现它们已被弃用之前,我还尝试了一些库。我也尝试过使用普通的 REST API 调用来做到这一点,但我得到了“禁止”响应。

我的 oauth2 库运行良好,因为我能够使用 GMail 实现相同的功能。

我们将不胜感激任何帮助或提示。

提前谢谢你。

最佳答案

为什么不这样做呢?

jcts = urlib2.urlopen(settings.HOTMAIL_USER_FRIENDS_URI % response['access_token'])
contacts = simplejson.loads(jcts)

关于python - Windows Live 登录 API SSL 问题 - Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10883992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com