SAML-Toolkits / python3-saml

MIT License
682 stars 304 forks source link

Flask example hits error: AttributeError: 'Request' object has no attribute 'netloc' #279

Closed brentgracey closed 3 years ago

brentgracey commented 3 years ago

Hi; thanks for the great library and well documented examples.

I am getting an exception on: https://github.com/onelogin/python3-saml/blob/master/demo-flask/index.py#L26 - I've edited the file a little bit locally; but its from line 26 in master.

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2301, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2287, in wsgi_app
    response = self.handle_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1733, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2284, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1807, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1710, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1805, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1791, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/brent/repos/v7labs-sso-egs/python3-saml/demo-flask/index.py", line 64, in index
    req = prepare_flask_request(request)
  File "/home/brent/repos/v7labs-sso-egs/python3-saml/demo-flask/index.py", line 53, in prepare_flask_request
    'http_host': request.netloc, # "localhost:8000",
AttributeError: 'Request' object has no attribute 'netloc'

For local testing I just hardcoded it; and the rest of the login flow works as expected. Would updating to one of the below be correct:

request.url:                 http://127.0.0.1:5000/alert/dingding/test?x=y
request.base_url:            http://127.0.0.1:5000/alert/dingding/test
request.url_root:            http://127.0.0.1:5000/
request.host_url:            http://127.0.0.1:5000/
request.host:                127.0.0.1:5000
request.script_root:

... abbreviated from https://stackoverflow.com/questions/15974730/how-do-i-get-the-different-parts-of-a-flask-requests-url

pitbulk commented 3 years ago

https://github.com/onelogin/python3-saml/commit/e77d015ba4ce077787fee321614dee86d78b583d