2017-01-16 4 views
4

다음 예를 기반으로 Google 인증을 사용하고 있습니다. 모든 것이 정상적으로 작동하고 있었고 로그인을 시도했을 때이 오류가 발생하기 시작했습니다.ServerNotFoundError : accounts.google.com에서 서버를 찾을 수 없습니다.

httplib2.ServerNotFoundError ServerNotFoundError: Unable to find the server at accounts.google.com

무엇이 잘못 되었습니까?

from flask import Flask, redirect, url_for, session 
from flask_oauth import OAuth 


# You must configure these 3 values from Google APIs console 
# https://code.google.com/apis/console 
GOOGLE_CLIENT_ID = '<Client-ID>' 
GOOGLE_CLIENT_SECRET = '<Client-secret>' 
REDIRECT_URI = '/authorized' # one of the Redirect URIs from Google APIs console 

SECRET_KEY = 'development key' 
DEBUG = True 

app = Flask(__name__) 
app.debug = DEBUG 
app.secret_key = SECRET_KEY 
oauth = OAuth() 

google = oauth.remote_app('google', 
          base_url='https://www.google.com/accounts/', 
          authorize_url='https://accounts.google.com/o/oauth2/auth', 
          request_token_url=None, 
          request_token_params={'scope': 'https://www.googleapis.com/auth/userinfo.email', 
               'response_type': 'code'}, 
          access_token_url='https://accounts.google.com/o/oauth2/token', 
          access_token_method='POST', 
          access_token_params={'grant_type': 'authorization_code'}, 
          consumer_key=GOOGLE_CLIENT_ID, 
          consumer_secret=GOOGLE_CLIENT_SECRET) 

@app.route('/') 
def index(): 
    access_token = session.get('access_token') 
    if access_token is None: 
     return redirect(url_for('login')) 

    access_token = access_token[0] 
    from urllib2 import Request, urlopen, URLError 

    headers = {'Authorization': 'OAuth '+access_token} 
    req = Request('https://www.googleapis.com/oauth2/v1/userinfo', 
        None, headers) 
    try: 
     res = urlopen(req) 
    except URLError, e: 
     if e.code == 401: 
      # Unauthorized - bad token 
      session.pop('access_token', None) 
      return redirect(url_for('login')) 
     return res.read() 

    return res.read() 


@app.route('/login') 
def login(): 
    callback=url_for('authorized', _external=True) 
    return google.authorize(callback=callback) 



@app.route(REDIRECT_URI) 
@google.authorized_handler 
def authorized(resp): 
    access_token = resp['access_token'] 
    session['access_token'] = access_token, '' 
    return redirect(url_for('index')) 


@google.tokengetter 
def get_access_token(): 
    return session.get('access_token') 


def main(): 
    app.run() 


if __name__ == '__main__': 
    main() 

답변

1

이전에이 문제가 있었으며 컴퓨터에서 IPv6를 사용하지 않도록 수정했습니다. 어떤 이유로 Google과 IPv6는 잘 작동하지 않습니다. 당신은 Mac의 경우

, 명령은 다음과 같습니다

sudo networksetup -setv6off wi-fi 

그것을 되돌릴 수 있는지 확인이 완료되면 :

sudo networksetup -setv6automatic wi-fi