OAuth Gdata Python客户端在RSA_密钥上抛出stacktrace
从AuthSub转到OAuth,我想我正在慢慢地开始理解这个过程。 但这一次给了我一个错误:OAuth Gdata Python客户端在RSA_密钥上抛出stacktrace,python,google-app-engine,gdata-api,gdata,Python,Google App Engine,Gdata Api,Gdata,从AuthSub转到OAuth,我想我正在慢慢地开始理解这个过程。 但这一次给了我一个错误: #!/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 gdat
#!/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_密钥字符串,我得到了一个stacktrace:
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
tlslite有两种密钥格式:PEM和XML。然后回到XML。显然,您的PEM文件中存在错误,因此PEM解析失败(但应该成功)。解析XML显然必须失败
我的猜测是,你在某种程度上弄乱了行尾,但也许PEM文件有更根本的问题。到目前为止,该应用程序除了显示一个链接供用户授权请求令牌外,不应该做任何事情。谢谢!我认为可能发生的事情是VisualStudio提供了转换行尾的功能,而我愚蠢地接受了。为了在google应用程序上工作,它们应该是LF还是CR-LF行结尾?我创建了一个新的PEM文件,但结果仍然是一样的。我将查找其他生成PEM文件的程序。是否有方法验证该文件?我建议您尝试直接调用parsePEMKey,以了解它不喜欢什么。好的,我直接调用了parsePrivateKey,解析“openssl genrsa 2048”生成的密钥的唯一问题是。现在我只需要弄清楚如何创建证书和密钥。。。完成。谢谢你的提示!!!出于好奇:“是吗?”。。。什么?