{"action":"created","issue":{"url":"https://api.github.com/repos/corydolphin/flask-cors/issues/196","repository_url":"https://api.github.com/repos/corydolphin/flask-cors","labels_url":"https://api.github.com/repos/corydolphin/flask-cors/issues/196/labels{/name}","comments_url":"https://api.github.com/repos/corydolphin/flask-cors/issues/196/comments","events_url":"https://api.github.com/repos/corydolphin/flask-cors/issues/196/events","html_url":"https://github.com/corydolphin/flask-cors/issues/196","id":213246554,"number":196,"title":"Why flask_cors didn't return response directly (before Decorator @before_request) when get a OPTIONS request?","user":{"login":"gasxia","id":9269304,"avatar_url":"https://avatars0.githubusercontent.com/u/9269304?v=3","gravatar_id":"","url":"https://api.github.com/users/gasxia","html_url":"https://github.com/gasxia","followers_url":"https://api.github.com/users/gasxia/followers","following_url":"https://api.github.com/users/gasxia/following{/other_user}","gists_url":"https://api.github.com/users/gasxia/gists{/gist_id}","starred_url":"https://api.github.com/users/gasxia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gasxia/subscriptions","organizations_url":"https://api.github.com/users/gasxia/orgs","repos_url":"https://api.github.com/users/gasxia/repos","events_url":"https://api.github.com/users/gasxia/events{/privacy}","received_events_url":"https://api.github.com/users/gasxia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2017-03-10T05:14:42Z","updated_at":"2017-03-22T17:32:05Z","closed_at":null,"body":"```python\r\ndef create_app(config_name):\r\n    app = Flask(__name__)\r\n    logging.getLogger('flask_cors').level = logging.DEBUG\r\n    CORS(app)\r\n    app.config.from_object(config[config_name])\r\n    config[config_name].init_app(app)\r\n\r\n    db.init_app(app)\r\n\r\n    # 注册api蓝本\r\n    from .api import api as api_blueprint\r\n    app.register_blueprint(api_blueprint, url_prefix='/api')\r\n    # todo: 处理路由与错误页面\r\n\r\n    return app\r\n```\r\nError In before_request\r\n`api/auth.py`\r\n```\r\nfrom flask import g, request\r\nfrom flask.ext.httpauth import HTTPBasicAuth\r\nfrom .errors import forbidden\r\nfrom flask_cors import cross_origin\r\nfrom . import api\r\nfrom ..models import User\r\n\r\nauth = HTTPBasicAuth()\r\n\r\n@auth.verify_password\r\ndef verify_password(username, password):\r\n    user = User.query.filter_by(username = username).first()\r\n    if not user:\r\n        return False\r\n    g.current_user = user\r\n    return user.verify_password(password)\r\n\r\n\r\n@api.before_request\r\n# @cross_origin()\r\n@auth.login_required\r\ndef before_request():\r\n    # pass\r\n    if not g.current_user: # request.method != 'OPTIONS' and not g.current_user:\r\n        return forbidden('Unconfirmed account')\r\n```\r\nWhen I send a auth fetch. I'm getting the error.\r\n```\r\n127.0.0.1 - - [10/Mar/2017 12:35:25] \"OPTIONS /api/posts/ HTTP/1.1\" 500 -\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1994, in __call__\r\n    return self.wsgi_app(environ, start_response)\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1985, in wsgi_app\r\n    response = self.handle_exception(e)\r\n  File \"/usr/local/lib/python2.7/site-packages/flask_cors/extension.py\", line 161, in wrapped_function\r\n    return cors_after_request(app.make_response(f(*args, **kwargs)))\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1540, in handle_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1982, in wsgi_app\r\n    response = self.full_dispatch_request()\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1614, in full_dispatch_request\r\n    rv = self.handle_user_exception(e)\r\n  File \"/usr/local/lib/python2.7/site-packages/flask_cors/extension.py\", line 161, in wrapped_function\r\n    return cors_after_request(app.make_response(f(*args, **kwargs)))\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1517, in handle_user_exception\r\n    reraise(exc_type, exc_value, tb)\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1610, in full_dispatch_request\r\n    rv = self.preprocess_request()\r\n  File \"/usr/local/lib/python2.7/site-packages/flask/app.py\", line 1831, in preprocess_request\r\n    rv = func()\r\n  File \"/usr/local/lib/python2.7/site-packages/flask_httpauth.py\", line 93, in decorated\r\n    return f(*args, **kwargs)\r\n  File \"/Users/jinrunsen/Dev/Projects/learn-flask/user-api/app/api/auth.py\", line 24, in before_request\r\n    if not g.current_user:# request.method != 'OPTIONS' and not g.current_user:\r\n  File \"/usr/local/lib/python2.7/site-packages/werkzeug/local.py\", line 343, in __getattr__\r\n    return getattr(self._get_current_object(), name)\r\nAttributeError: '_AppCtxGlobals' object has no attribute 'current_user'\r\n```\r\nWhy flask_cors didn't return response directly (before Decorator `@before_request`) when get a `OPTIONS` request?"},"comment":{"url":"https://api.github.com/repos/corydolphin/flask-cors/issues/comments/288477444","html_url":"https://github.com/corydolphin/flask-cors/issues/196#issuecomment-288477444","issue_url":"https://api.github.com/repos/corydolphin/flask-cors/issues/196","id":288477444,"user":{"login":"corydolphin","id":446889,"avatar_url":"https://avatars2.githubusercontent.com/u/446889?v=3","gravatar_id":"","url":"https://api.github.com/users/corydolphin","html_url":"https://github.com/corydolphin","followers_url":"https://api.github.com/users/corydolphin/followers","following_url":"https://api.github.com/users/corydolphin/following{/other_user}","gists_url":"https://api.github.com/users/corydolphin/gists{/gist_id}","starred_url":"https://api.github.com/users/corydolphin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/corydolphin/subscriptions","organizations_url":"https://api.github.com/users/corydolphin/orgs","repos_url":"https://api.github.com/users/corydolphin/repos","events_url":"https://api.github.com/users/corydolphin/events{/privacy}","received_events_url":"https://api.github.com/users/corydolphin/received_events","type":"User","site_admin":false},"created_at":"2017-03-22T17:32:05Z","updated_at":"2017-03-22T17:32:05Z","body":"Hmm, sorry for the trouble here @gasxia I think this may be related to the intercept_exceptions option misbehaving.\r\n\r\nCan you try to disable 'intercept_exceptions' by setting `intercept_exceptions=false` and let me know if that fixes things?"}}
{"actor":{"display_login":"corydolphin"}}