I've searched throughly on stack overflow and google about this error and I couldn't find the solution that resolves my situation.
I'm using marshmallow to serialize/deserialize my api get request.
@post_user_blueprint.route('/api/v1/get_current_profile', methods=['GET'])
@login_required
def get_profile():
query_user_by_order = User.query.join(Sample) \
.join(Individual) \
.join(Ordering) \
.join(Family) \
.join(Sequence) \
.filter(User.id == Sample.fk_user_id) \
.filter(Individual.id == Sample.fk_individual_id) \
.filter(Sample.id == Sequence.fk_sample_id) \
.filter(Individual.id == Ordering.fk_individual_id) \
.filter(Family.id == Individual.fk_family_id) \
.filter(User.email == current_user.email)\ ***********
.all()
result = profile_users_schema.dump(query_user_by_order)
return jsonify({'user': result.data})
@login_required
@post_user_blueprint.route('/profile', methods=['GET', 'POST'])
def profile():
response = requests.get('http://127.0.0.1:5000/api/v1/get_current_profile')
response = response.text
data = json.loads(response) $$$$$$$$$$$$$$$$$
return render_template('profile.html', user_object = data)
***** : when I omit this line, this works fine, the only reason that I'm adding that line is to show whoever logged in his/her profile instead of showing everyone's profile. $$$$$ : This is the line of error.
Full TraceBack
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 2000, in __call__
return self.wsgi_app(environ, start_response)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1991, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1567, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1988, in wsgi_app
response = self.full_dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1641, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask_restful/__init__.py", line 271, in error_router
return original_handler(e)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1544, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1639, in full_dispatch_request
rv = self.dispatch_request()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1625, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/genomics/PycharmProjects/sample_accessioning/app/views/post_inputs.py", line 209, in profile
profile = response.json()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/requests/models.py", line 826, in json
return complexjson.loads(self.text, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
I do not understand why this is happening, the ****** line is not directly showing its error after I put @login_required right above def get_profile. But when the @login_required was not there, it was throwing
AttributeError: 'AnonymousUser' object has no attribute 'email'
If possible I would like to know a way of getting current user's email so I can query current user's profile instead of whole. Also, I really want to know why below error is occurring.
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Thanks,