Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

self.__logout_response is not bytes that make lxml error #95

Closed
linnil1 opened this issue May 4, 2018 · 3 comments · Fixed by #127
Closed

self.__logout_response is not bytes that make lxml error #95

linnil1 opened this issue May 4, 2018 · 3 comments · Fixed by #127

Comments

@linnil1
Copy link

linnil1 commented May 4, 2018

Hi,
I run the code just almost same as demo-flask.
And when it run to this line
redirect(auth.logout(name_id=name_id, session_index=session_index)).
This is error output:

[2018-05-04 22:26:48,887] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/app/LoginWeb/tzfserver/start.py", line 88, in Login
    url = auth.process_slo(delete_session_cb=dscb)
  File "/usr/local/lib/python3.6/site-packages/onelogin/saml2/auth.py", line 144, in process_slo
    logout_response = OneLogin_Saml2_Logout_Response(self.__settings, get_data['SAMLResponse'])
  File "/usr/local/lib/python3.6/site-packages/onelogin/saml2/logout_response.py", line 42, in __init__
    self.document = OneLogin_Saml2_XML.to_etree(self.__logout_response)
  File "/usr/local/lib/python3.6/site-packages/onelogin/saml2/xml_utils.py", line 65, in to_etree
    return OneLogin_Saml2_XML._parse_etree(xml)
  File "/usr/local/lib/python3.6/site-packages/defusedxml/lxml.py", line 143, in fromstring
    rootelement = _etree.fromstring(text, parser, base_url=base_url)
  File "src/lxml/etree.pyx", line 3213, in lxml.etree.fromstring
  File "src/lxml/parser.pxi", line 1871, in lxml.etree._parseMemoryDocument
ValueError: Unicode strings with encoding declaration are not supported. Please use bytes input or XML fragments without declaration.

with

  • python 3.6.4
  • Flask (1.0.2)
  • gunicorn (19.8.1)
  • lxml (4.2.1)
  • python3-saml (1.4.1)
  • xmlsec (1.3.3)

I solve it by modifying logout_response.py
to this self.document = OneLogin_Saml2_XML.to_etree(self.__logout_response.encode())

Do I have wrong configuration that makes this error?

@pitbulk
Copy link
Contributor

pitbulk commented May 5, 2018

what value had the nameid?

@linnil1
Copy link
Author

linnil1 commented May 5, 2018

Just same as demo code
After login,
auth.get_nameid() is store in session.
session['samlNameId'] = auth.get_nameid()
And before logout,
name_id is restore from session['samlNameId']

name_id = session['samlNameId']
return redirect(auth.logout(name_id=name_id, session_index=session_index))

@omardlhz
Copy link

@linnil1 Was this issue ever resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants