2016-11-14 112 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

相关问题