2016-11-14 106 views
0

我正在使用API​​調用實體提取來處理https://dandelion.eu/。我發送文本文件並自動回覆一個json文件作爲響應。這不是我第一次使用這項服務,它的運作非常好。現在我開始發送一組新的文本文件,其中使用了我始終使用的相同參數,但是我得到了這個:ValueError:太多值來解壓縮。 這裏是我的代碼:Python requests.request ValueError:解壓縮的值太多

values={"text":" ", 
     "min_confidence":"0.6", 
     "include":"types", 
     "include":"abstract", 
     "include":"categories" 
     } 

headers = {'X-Target-URI':'https://api.dandelion.eu', 
      'Host':'api.dandelion.eu', 
      'Connection': 'keep-alive', 
      'Server': 'Apache-Coyote/1.1', 
      'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', 
      } 

for roots, dirs, files in os.walk(spath): #spath is specified 
for file in files: 
    if file.startswith("A0"): 
     with open(file, "r") as f: 
      text = f.read() 

      values["text"]= " ".join(text.split()) 

      #api call 
      url = "https://api.dandelion.eu/datatxt/nex/v1/" 
      data = urllib.urlencode(values, "utf-8") 
      response = requests.request("POST", url, data=data, headers=headers, params=token_api) 

      content = response.json() 

      print content 

ErrorValue:值過多解壓

有人可以幫我在這?我總是使用相同的代碼進行其他API調用,並且它運行良好。我現在不知道什麼是錯。

回答

0

API返回多個值。

請參考API文檔,看看返回值是什麼。

(你沒有提到API在瀏覽問題中提出了哪些錯誤)

+0

這看起來很奇怪,因爲API總是給出單個響應。一個sigle json文件。我對其他文本文件使用相同的python腳本,並且它可以正常工作。 – CosimoCD

+0

我發現了什麼問題...我的文件的標題是越來越多的數字,es。 001,00002。我不知道爲什麼,但是當我說python打開所有以「0」開頭的文件時,它會一個接一個地打開所有文件,但兩次打開同一個文件。因此,它將兩個文件存儲在變量值[「text」] =「」.join(text.split())中,當我收回響應時,無法解壓縮。 – CosimoCD

相關問題