Sfoglia il codice sorgente

Safer parsing for Turnitin API result.

copyvios-ng
Ben Kurtovic 6 anni fa
parent
commit
a63e4e2236
1 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. +5
    -3
      copyvios/turnitin.py

+ 5
- 3
copyvios/turnitin.py Vedi File

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

import requests
@@ -31,8 +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
parsed_api_result = literal_eval(result.text)
try:
parsed_api_result = json.loads(result.text)
except ValueError:
parsed_api_result = []
return parsed_api_result

class TurnitinResult(object):


Caricamento…
Annulla
Salva