瀏覽代碼

Revert previous; literal_eval is necessary here. Add error handling.

copyvios-ng
Ben Kurtovic 6 年之前
父節點
當前提交
29861c1118
共有 1 個文件被更改,包括 4 次插入3 次删除
  1. +4
    -3
      copyvios/turnitin.py

+ 4
- 3
copyvios/turnitin.py 查看文件

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import json
from ast import literal_eval
import re

import requests
@@ -31,9 +31,10 @@ def _make_api_request(page_title, lang):
'report': 1}

result = requests.get(TURNITIN_API_ENDPOINT, params=api_parameters)
# use literal_eval to *safely* parse the resulting dict-containing string
try:
parsed_api_result = json.loads(result.text)
except ValueError:
parsed_api_result = literal_eval(result.text)
except (SyntaxError, ValueError):
parsed_api_result = []
return parsed_api_result



Loading…
取消
儲存