2012-05-09 13 views
1

私は、javascriptでユーザーを認証し、アクセストークンを取得するためにcookieからfacebook_request情報を読み取るアプリケーションを構築していますサーバーで使用するためのものです。 私はsslハンドシェイクでタイムアウトエラーを打ち続ける。SSLCertificateError - facebookからアクセストークンを取得しようとしたときに「ハンドシェイク操作がタイムアウトしました」

これは私が

 logger.debug("authenticate with %s" % facebook_id) 
    payload = {'client_id': settings.FACEBOOK_APP_ID, 
       'client_secret': settings.FACEBOOK_APP_SECRET, 
       'code': code , 
       'redirect_uri': settings.FACEBOOK_DEFAULT_REDIRECT_URI} 
    url = 'https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(payload) 
    access_token, status, headers = urlfetch.fetch(
             url=url, 
             deadline=30, 
             validate_certificate=False 
            ) 
    logger.debug("recieved access token from fb %s" % access_token) 

を使用していたコードは、このエラーで失敗している:@BluesRockAddictが提案されているよう

DEBUG 2012-05-09 21:27:33,956 backends.py:24] authenticate with 546941722 
DEBUG 2012-05-09 21:27:33,956 urlfetch_stub.py:317] Making HTTP request: host = graph.facebook.com, url = https://graph.facebook.com/oauth/access_token?client_secret=999&code=999&client_id=229985173769038&redirect_uri=http%3A%2F%2Fdev.bitesizedbeautyapp.appspot.com%2F, payload = , headers = {'Host': 'graph.facebook.com', 'Accept-Encoding': 'gzip', 'User-Agent': 'AppEngine-Google; (+http://code.google.com/appengine)'} 
ERROR 2012-05-09 21:28:04,130 __init__.py:63] Exception in request: 
Traceback (most recent call last): 
    File "/work/glow/bitesizedbeauty/django/core/handlers/base.py", line 89, in get_response 
    response = middleware_method(request) 
    File "/work/glow/bitesizedbeauty/bitesizedbeautyapp/facebook_glue/middleware.py", line 27, in process_request 
    user = authenticate(facebook_id = fb_uid, code = code) 
    File "/work/glow/bitesizedbeauty/django/contrib/auth/__init__.py", line 55, in authenticate 
    user = backend.authenticate(**credentials) 
    File "/work/glow/bitesizedbeauty/bitesizedbeautyapp/facebook_glue/backends.py", line 33, in authenticate 
    validate_certificate=False 
    File "/usr/local/google_appengine/google/appengine/api/urlfetch.py", line 263, in fetch 
    return rpc.get_result() 
    File "/usr/local/google_appengine/google/appengine/api/apiproxy_stub_map.py", line 592, in get_result 
    return self.__get_result_hook(self) 
    File "/usr/local/google_appengine/google/appengine/api/urlfetch.py", line 374, in _get_fetch_result 
    raise SSLCertificateError(str(err)) 
SSLCertificateError: ApplicationError: 6 _ssl.c:488: The handshake operation timed out 

編集

はまだエラーを取得、コードを変更し

編集#2

解決済み!多くのランダムな異なるものであることが判明しました。

  • GET要求の必要に応じて、URLにパラメータを追加します。私はクライアントSDKを使用してユーザーを認証し、コード要素をfbsr_クッキーから読み取っています。この場合、redirect_uriは空でなければなりません。
  • app-engineのurlfetchは私が思ったように3タプルを返しません。私は、単一の変数ここ

にメソッドの結果が割り当てられて私のために動作するコードは次のとおりです。

def get_auth_token(code=None): 
    if not code: 
     return Null 
    try: 
     payload = {'client_id': settings.FACEBOOK_APP_ID, 
        'client_secret': settings.FACEBOOK_APP_SECRET, 
        'code': code, 
        'redirect_uri': ''} 

     url = 'https://graph.facebook.com/oauth/access_token?' + urllib.urlencode(payload) 
     logging.debug("url going to be called = (%s)" % url) 
     result = urlfetch.fetch(
      url=url, 
      deadline=10, 
      validate_certificate=False 
     ) 
     access_token = result.content 
     logging.info("recieved access_token from fb %s" % access_token) 
    except SSLCertificateError as error: 
     logging.error("SSLCertificateError when accessing oauth/access_token, error = %s " % error) 
     return None 
    except Exception as error2: 
     logging.error("Other Error, error = %s " % error2) 
     return None 

答えて

1

​​引数は、POST/PUT要求に対してのみ使用してください。 GETを使用しているため、ペイロードデータをURLに含める必要があります。以下を試してください:

access_token, status, headers = urlfetch.fetch(
    "https://graph.facebook.com/oauth/access_token?" + 
    urllib.urlencode(payload)) 
+0

あなたの答えをありがとう、私はあなたの提案を変更しました。しかし、私はまだエラーを取得しています。 –

+0

次の場合はどうなりますか? '応答= cgi.parse_qs(urllib.urlopen( " https://graph.facebook.com/oauth/access_token?urllib.urlencode(payload))。read()) ' – BluesRockAddict

+0

これは、数分 - それは戻っていない –

関連する問題