스택 오버플로 및 Google에서이 오류에 대해 검색 한 결과 내 상황을 해결하는 솔루션을 찾을 수 없습니다.Flask Json json.decoder.JSONDecodeError : 예상 값 : 1 행 1 (char 0)
marshmallow를 사용하여 API 요청을 serialize/deserialize하고 있습니다.
@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)
***** :이 라인을 생략 할 경우,이 잘 작동, 나는 그 라인을 추가 해요 유일한 이유는 모든 사람의 프로필을 게재하는 대신 그/그녀의 프로필에 기록 누구든지 보여주는 것입니다. $$$$$ : 이것은 오류의 줄입니다.
전체 역 추적
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)
이런 일이 왜 이해가 안 돼요, 내가 바로 데프 get_profile 위 @login_required 넣어 후 ****** 라인이 직접 오류가 표시되지 않습니다. @login_required가 없을 때 나는 그래서 전체 대신 현재 사용자의 프로필을 조회 할 수 있습니다 현재 사용자의 이메일을 받고하는 방법을 알고 싶습니다 가능하다면, 그것은
AttributeError: 'AnonymousUser' object has no attribute 'email'
를 던지고 있었다. 또한, 나는 왜 아래의 오류가 발생 하는지를 정말로 알고 싶다.
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
덕분에,
당신이 대답을 찾았 기쁘다. 실제로 응답에'decode' 메소드를 사용하지 않고 응답을 유니 코드 문자열로 얻는 더 좋은 방법이 있습니다. 'get_data()'메소드를 사용하기 만하면된다. 'data' 속성은 실제로 http://flask.pocoo.org/docs/0.12/api/#flask.Response에서 언급 한 것처럼 결국은 더 이상 사용되지 않을 것입니다.데이터 죄송합니다. 내 잘못입니다. '.data'를'.get_data (as_text = True)'로 변경하면'.decode ('utf-8')'을 사용하지 않아야합니다. 이 답변을 반영하여 답변을 업데이트했습니다. 작동하는지 알려 주시기 바랍니다. – AArias
9 개월 후에도 유효하고 아직 실제로 문제가 해결되지 않은 이유는 무엇입니까? 내가 당신을 도울 시간을 가졌기 때문에 냉담하지 않았습니다. – AArias