Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

python 2.7 - AttributeError: 'Request' object has no attribute 'is_xhr'

I am trying to run cuckoo api. Cuckoo web is working fine on my system. But when I tried cuckoo api, I got the following error:

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 -

I tried to change api.py by adding the following code:

@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')

But that didn't help me. What could be the solution to this issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Per this github issue, another option is to disable JSONIFY_PRETTYPRINT_REGULAR in your config file.

class Config:
  # Other configs
  JSONIFY_PRETTYPRINT_REGULAR = False

or

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...