Код:
def get_result(response_path):
response_s3_path = re.sub(config.path_prefix,'',response_path).strip('/')
print('== response_s3_path')
print(response_s3_path)
response_local_path = download_file_from_s3(response_s3_path)
print('== response_local_path')
print(response_local_path)
if response_local_path==-1:
print('Failed to open response_local path')
return -1
with open(response_local_path, 'r') as f:
print(type(json.load(f)))
print(json.load(f))
if isinstance(json.load(f), str):
response = json.loads(json.load(f))
#response = json.load(f)
elif isinstance(json.load(f), dict):
print('json.loads(dict)')
response = json.load(f)
Вывод вставленных операторов печати:
== response_s3_path
AAAA/XXXX/response.json
== response_local_path
./tmp/response.json
<class 'dict'>
{'success': True, 'message': 'Device detected', 'data': {'areas': 2, 'num': 43, 'probability_x': 0.8843076229095459, 'probability_n-x': 0.9764912003694579, 'grids': [ [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]], 'test123': False, 'deviceDetected': True, 'unique_file_index': 'xxxx', 'sensorLogURL': 'https://xxxxx/'}}
Сообщение об ошибке опубликовать вывод:
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/AjayB/Desktop/Python/crackd/misc/training_apis/training_apis_server/Apis/views.py", line 1141, in get_inference_results_api
_, inference_array = get_inference_results_from_df(df_pass)
File "/Users/AjayB/Desktop/Python/crackd/misc/training_apis/training_apis_server/Apis/views.py", line 1260, in get_inference_results_from_df
inference_array = get_inference_array(inference_links)
File "/Users/AjayB/Desktop/Python/crackd/misc/training_apis/training_apis_server/Apis/views.py", line 721, in get_inference_array
final_response_params = get_result(obj_tmp['response']['path'])
File "/Users/AjayB/Desktop/Python/crackd/misc/training_apis/training_apis_server/Apis/views.py", line 644, in get_result
print(isinstance(json.load(f), dict))
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/json/__init__.py", line 299, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/json/__init__.py", line 354, in loads
return _default_decoder.decode(s)
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Users/AjayB/anaconda3/envs/MyDjangoEnv/lib/python3.6/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)
[08/Nov/2019 05:49:38] "POST /list/inference_history/ HTTP/1.1" 500 147054
Неспособность понять, что если json.load (f) имеет класс ' dict ', и при печати, если он кажется допустимым словарем, то почему он выдает мне JsonDecodeError в строке:
elif isinstance(json.load(f), dict):
?
Пожалуйста, помогите.