尝试Google Oauth Flow的Step2时出现ServerNotFound错误

时间:2015-08-11 16:23:20

标签: python django python-2.7 oauth google-oauth2

当我尝试完成Google Oauth2流程中的第2步时,我收到了SeverNotFound错误。这在最初测试时起作用但由于某种原因我现在一直得到这个错误。我在Django 1.8中运行Python 2.7。以下是发送代码的视图。

def social(request):
    code = request.GET.get('code', 'null')
    credentials = FLOW.step2_exchange(code)
    http_auth = credentials.authorize(httplib2.Http())
    plus_service = build('oauth2', 'v2', http=http_auth)
    profile = plus_service.userinfo().get().execute()
    first = profile['given_name']
    last = profile['family_name']
    email = profile['email']
    password = User.objects.make_random_password()
    user = User.objects.create_user(email, email, password, first_name=first, last_name=last)
    return HttpResponse("The user was registered as id %s" % user.id)

例外:

ServerNotFoundError at /pd/social/
Unable to find the server at accounts.google.com
Request Method: GET
Request URL:    http://pd.com:8000/pd/social/?code=4/Rag-paWm44EnLwAwKXMfmY-UiaipntZjkCIKyUhYjWE&authuser=0&session_state=22ef0a1815d40f96ef08135bc37886bdb0986e9d..6846&prompt=none
Django Version: 1.8.3
Exception Type: ServerNotFoundError
Exception Value:    
Unable to find the server at accounts.google.com
Exception Location: /usr/local/lib/python2.7/dist-packages/httplib2/__init__.py in _conn_request, line 1278
Python Executable:  /usr/bin/python
Python Version: 2.7.6
Python Path:    
['/usr/cordeco/dugout',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages']
Server time:    Tue, 11 Aug 2015 06:27:49 +0000

这是追溯:

请求方法:GET 请求网址:http://pd.com:8000/pd/social/?code=4/f7qAKhDZxasmjT9eLbuZXykY9fhkSj8_6k6VZ5BAM8A&authuser=0&session_state=22ef0a1815d40f96ef08135bc37886bdb0986e9d..6846&prompt=none

Django Version: 1.8.3
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'pd')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')

回溯:

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/cordeco/dugout/pd/views.py" in social
  27.     credentials = FLOW.step2_exchange(code)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/util.py" in positional_wrapper
  137.       return wrapped(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/oauth2client/client.py" in step2_exchange
  1993.                                  headers=headers)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py" in request
  1608.                     (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py" in _request
  1350.         (response, content) = self._conn_request(conn, request_uri, method, body, headers)
File "/usr/local/lib/python2.7/dist-packages/httplib2/__init__.py" in _conn_request
  1278.                 raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
  

异常类型:/ pd / social /

中的ServerNotFoundError      

例外值:无法在accounts.google.com

找到服务器

0 个答案:

没有答案