Link to home
Start Free TrialLog in
Avatar of khugfyg jatdyh
khugfyg jatdyh

asked on

AttributeError: 'unicode' object has no attribute 'get'

from flask.ext.api import FlaskAPI
from flask import request, current_app, abort
from functools import wraps

app = FlaskAPI(__name__)
app.config.from_object('settings')

def token_auth(f):
    @wraps(f)
    def decorated_function(*args, **kwargs):
        if request.headers.get('X-API-TOKEN', None) != current_app.config['API_TOKEN']:
            abort(403)
        return f(*args, **kwargs)
    return decorated_function

@app.route('/predict', methods=['POST'])
@token_auth
def predict():
    from big_model import model
    item = request.data.get('item')
    total_predictions = request.data.get('num', 100)
    if not item:
        return []
    return model.predict(str(item), total_predictions)


@app.route('/train')
@token_auth
def train():
    from big_model import model
    data_url = request.data.get('data-url', None)
    model.train(data_url)
    return {"message": "Success!", "success": 1}

if __name__ == '__main__':
    app.debug = True
    app.run()
Avatar of pepr
pepr

Where? At what line?
Avatar of khugfyg jatdyh

ASKER

File "web.py", line 13, in decorated_function
    return f(*args, **kwargs)
  File "web.py", line 20, in predict
    item = request.data.get('item')
AttributeError: 'unicode' object has no attribute 'get'
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: pepr (https:#a42252414)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

suhasbharadwaj
Experts-Exchange Cleanup Volunteer