属性错误:"请求"对象没有属性"is_xhr"



我正在尝试运行布谷鸟api。布谷鸟网在我的系统上运行良好。但当我尝试杜鹃api时,我得到了以下错误:

File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1512, in handle_user_exception
return self.handle_http_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1471, in handle_http_exception
return handler(e)
File "/usr/local/lib/python2.7/dist-packages/cuckoo/apps/api.py", line 719, in api_auth_required
401, "Authentication in the form of an "
File "/usr/local/lib/python2.7/dist-packages/cuckoo/apps/api.py", line 36, in json_error
r = jsonify(message=message)
File "/usr/local/lib/python2.7/dist-packages/flask/json.py", line 251, in jsonify
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:
File "/usr/local/lib/python2.7/dist-packages/werkzeug/local.py", line 347, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: 'Request' object has no attribute 'is_xhr'
2020-04-02 18:50:39,640 [werkzeug] INFO: 192.168.100.94 - - [02/Apr/2020 18:50:39] "GET / HTTP/1.1" 500 -

我试图通过添加以下代码来更改api.py:

@app.route("/publish/epoch/end/", methods=['POST'])
def publish():
#payload = request.form.get('data')
payload = unquote(request.data.split('=')[1]).replace('+','')
try:
`enter code here` data = json.loads(payload)
except:
return {'error':'invalid payload'}
def notify():
msg = str(time.time())
for sub in subscriptions[:]:
sub.put(payload)
gevent.spawn(notify)
return "OK"
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
model.save()
# Failure to return a redirect or render_template
else:
return render_template('index.html')

但这对我没有帮助。这个问题的解决方案是什么?

对于这个github问题,另一个选项是在配置文件中禁用JSONIFY_RETTYPRINT_REGULAR。

class Config:
# Other configs
JSONIFY_PRETTYPRINT_REGULAR = False

app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False

自Werkzeug 0.13以来,request.is_xhr属性已被弃用,并在Werkzeug1.0.0中被删除。使用Flask<=时会出现此错误0.12.4和Werkzeug>1.0.0,因为Flask在1.0.0版本之前的源代码中使用了此属性。您只需升级Flask(>=1.0.0(即可修复此问题:

$ pip install -U flask

否则,您也可以将Werkzeug降级至0.16.1:

$ pip install werkzeug==0.16.1

request.is_xhr方法已被弃用&删除,因为它不可靠。请参阅此处和此处关于删除原因的讨论。

您可能需要将Werkzeug的本地版本固定到与Cuckoo的固定版本Flask兼容的东西上(此处为示例(,直到Cuckoo更新到更新版本的Flask。

相关内容

  • 没有找到相关文章

最新更新