2011-01-17 7 views
0

AuthSubからOAuthに移行すると、私はゆっくりとプロセスを理解し始めていると思います。 この1は、しかし私にエラーを投げた:OAuth Gdata Python ClientがRSA_KEYでスタックトレースをスローする

#!/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文字列を読み込むしようとしている、と私はスタックトレースを取得するかのように表示されます:PEMとXML:

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は2 keyformatsを持っています。それはfirst tries PEM (see parsePrivateKey)であり、XMLにフォールバックします。どうやら、あなたのPEMファイルにエラーがあるので、PEM解析は失敗します(しかし、成功しているはずです)。 XMLの解析は、明らかに失敗する必要があります。

私は、どういうわけか、行末を混乱させていると思いますが、おそらくPEMファイルに根本的な問題があります。

+0

ありがとうございます!私は起こったかもしれないと思うのは、Visual Studioが行末を変換することを提案し、私が愚かに受け入れたということです。 Google Appsで動作するには、LFまたはCR-LFの行末にする必要がありますか? – lowerkey

+0

新しいPEMファイルを作成しましたが、結果は変わりません。私は、PEMファイルを生成する他のプログラムについて見ていきます。ファイルを確認する方法はありますか? – lowerkey

+0

parsePEMKeyを直接呼び出して、嫌いなものを見つけることをお勧めします。 –

関連する問題