2011-01-17 2 views
0

AuthSub에서 OAuth로 이동하면 서서히 프로세스를 이해하기 시작했습니다. 이 사람은 비록 나에게 오류가 발생했습니다 :OAuth Gdata Python 클라이언트가 RSA_KEY에서 stacktrace를 throw합니다.

#!/usr/bin/env python 

from google.appengine.ext import webapp 
from google.appengine.ext.webapp import util 
from google.appengine.ext.webapp import template 
from gdata.calendar import service 
import gdata 
from gdata.alt.appengine import run_on_appengine 

from google.appengine.api import users 
from google.appengine.ext import db 

from gdata.auth import OAuthSignatureMethod, OAuthToken, OAuthInputParams 
import urllib 
import simplejson 

import gdata.gauth 

from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError 

SCOPES = 'https://www.google.com/calendar/feeds/' # in this case just one, but for future reference, just concatenate different scopes with a space in between 
CONSUMER_KEY = 'jmm-timeline.appspot.com' 
CONSUMER_SECRET = 'consumer secret key, here' 
SIG_METHOD = gdata.auth.OAuthSignatureMethod.RSA_SHA1 
f = open('remotekey.pem') 
RSA_KEY = f.read() 
f.close() 


# Incomplete bibliography 
# http://www.youtube.com/watch?v=bfgO-LXGpTM 
# http://code.google.com/appengine/articles/python/retrieving_gdata_feeds.html 


class BasePage(webapp.RequestHandler): 
    title = "Joshua's Construction Zone" 
    def write_page_header(self): 
     self.response.out.write(template.render('templates/header.html', {'title': self.title})) 

    def write_page_footer(self): 
     self.response.out.write(template.render('templates/footer.html', {})) 

class MainHandler(BasePage): 
    def get(self): 

     self.write_page_header() 

     try: 
      client = gdata.calendar.service.CalendarService(source='jmm-timeline-v1') 
      run_on_appengine(client) 
      client.SetOAuthInputParameters(gdata.auth.OAuthSignatureMethod.RSA_SHA1, consumer_key=CONSUMER_KEY, consumer_secret=CONSUMER_SECRET, rsa_key=RSA_KEY) 
      req_token = client.FetchOAuthRequestToken(SCOPES) 
      oauth_callback_url = 'http://jmm-timeline.appspot.com/handle_authorized_request_token' 
      oauth_authorization_url = client.GenerateOAuthAuthorizationURL(callback_url=oauth_callback_url) 
      self.response.out.write(template.render('templates/authorization_prompt.html', { 'authorization_url': oauth_authorization_url })) 
     except CapabilityDisabledError, e: 
      self.response.out.write(template.render('templates/content/maintenance.html')) 

     self.write_page_footer() 

class HandleAuthorizedRequestToken(BasePage): 
    def get(self): 
     self.write_page_header() 

     client = gdata.calendar.service.CalendarService('jmm-timeline-2'); 
     run_on_appengine(client) 


     self.write_page_footer() 

def main(): 
    application = webapp.WSGIApplication([('/', MainHandler), ('/handle_authorized_request_token', HandleAuthorizedRequestToken)], debug=True) 
    util.run_wsgi_app(application) 


if __name__ == '__main__': 
    main() 

GDATA 내 RSA_KEY 문자열을 읽으려고하는 것처럼 그것은 나타나고, 나는 스택 트레이스 얻을 :

Traceback (most recent call last): 
    File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__ 
    handler.get(*groups) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\main.py", line 52, in get 
    req_token = client.FetchOAuthRequestToken(SCOPES) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\service.py", line 415, in FetchOAuthRequestToken 
    extra_parameters=extra_parameters) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\auth.py", line 217, in GenerateOAuthRequestTokenUrl 
    oauth_input_params.GetConsumer(), None) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\oauth\__init__.py", line 171, in sign_request 
    self.set_parameter('oauth_signature', self.build_signature(signature_method, consumer, token)) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\oauth\__init__.py", line 175, in build_signature 
    return signature_method.build_signature(self, consumer, token) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\oauth\rsa.py", line 55, in build_signature 
    privatekey = keyfactory.parsePrivateKey(cert) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\keyfactory.py", line 203, in parsePrivateKey 
    return parseXMLKey(s, private=True) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\keyfactory.py", line 79, in parseXMLKey 
    key = Python_RSAKey.parseXML(s) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\Python_RSAKey.py", line 137, in parseXML 
    element = xmltools.parseAndStripWhitespace(s) 
    File "C:\Users\Joshua\appengineapps\jmm-timeline\gdata\tlslite\utils\xmltools.py", line 30, in parseAndStripWhitespace 
    raise SyntaxError(str(e)) 
SyntaxError: syntax error: line 1, column 0 
+0

지금까지이 앱은 사용자가 요청 토큰을 승인 할 수있는 링크를 표시하는 것으로되어 있지 않습니다. – lowerkey

답변

2

tlslite이 두 keyformats : PEM 및 XML을 . 그것은 first tries PEM (see parsePrivateKey), 그리고 다시 XML로 떨어집니다. 분명히 PEM 파일에 오류가 있기 때문에 PEM ​​구문 분석에 실패하지만 실패했을 것입니다. XML 구문 분석은 분명히 실패해야합니다.

내 생각 엔 당신이 줄 결말을 어떻게 든 엉망으로 만들었지 만 PEM 파일에 근본적으로 잘못된 것이 있습니다.

+0

감사합니다. 무슨 일이 일어 났을 지 생각해 보면 Visual Studio가 줄 끝을 변환하고 어리석게 받아 들일 것을 제안했습니다. Google 앱에서 작동하려면 LF 또는 CR-LF 라인 결말이어야합니까? – lowerkey

+0

새로운 PEM 파일을 만들었지 만 그 결과는 여전히 동일합니다. PEM 파일을 생성하는 다른 프로그램을 살펴 보겠습니다. 파일을 확인하는 방법이 있습니까? – lowerkey

+0

싫어하는 점을 찾으려면 parsePEMKey를 직접 호출하는 것이 좋습니다. –

관련 문제