我正在尝试让 Flask-openid 正常工作,但在尝试登录时一直遇到此错误
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.
使用此功能时会发生
oid.try_login(openid, ask_for=['email', 'fullname', 'nickname'])
这是使用该功能的地方:
@app.route('/login', methods=['GET', 'POST'])
@oid.loginhandler
def login():
"""Does the login via OpenID. Has to call into `oid.try_login`
to start the OpenID machinery.
"""
# if we are already logged in, go back to were we came from
if g.user is not None:
app.logger.info('logged-in: ' + oid.get_next_url())
return redirect(oid.get_next_url())
if request.method == 'POST':
openid = request.form.get('openid_identifier')
if openid:
app.logger.info(request.form)
app.logger.info('logging-in: ' + oid.get_next_url())
return oid.try_login(openid, ask_for=['email', 'fullname',
'nickname'])
app.logger.info('not-logged-in: ' + oid.get_next_url())
return render_template('login.html', next=oid.get_next_url(),
error=oid.fetch_error())
实际上似乎是 Flask-openid 使用的 lxml 的问题:
File "C:\Python33\lib\site-packages\openid\yadis\etxrd.py", line 69, in parseXRDS
element = ElementTree.XML(text)
File "lxml.etree.pyx", line 3012, in lxml.etree.XML (src\lxml\lxml.etree.c:67876)
File "parser.pxi", line 1781, in lxml.etree._parseMemoryDocument (src\lxml\lxml.etree.c:102435)
我在 github 上尝试了几个示例项目,但它们都有相同的问题。有什么方法可以让 Flask-openid 在 Python 3 中工作吗?