2014-09-18 39 views
1

我試圖讓燒瓶OpenID的工作,而是不斷嘗試登錄可以用Python瓶-openid的問題3

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()) 

,實際上似乎是lxml的一個問題,燒瓶OpenID的用途:

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中工作?

回答

0

我只是在學習Flask自己,所以我沒有太大的幫助。

但是看看http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins

作者提到

注意的是,由於Python 2和3之間以unicode處理的差異,我們必須提供該方法的兩個替代版本。

他使用的str代替unicode

def get_id(self): 
    try: 
     return unicode(self.id) # python 2 
    except NameError: 
     return str(self.id) # python 3 

我可能是完全錯誤的!在這種情況下,我很抱歉,值得一試。

0

它不僅僅是字符串。它基於一個較老的python-openid軟件包,它不是Python3兼容的。 Python3專門有一個新版本的python-openid。

https://pypi.python.org/pypi/python3-openid/3.0.1

前面提到的還詳細介紹這個

同博客: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins 「不幸的是版本燒瓶的OpenID的1.2.1(目前官方版本)不使用Python很好地工作3.檢查是否有什麼版本的運行以下命令:「