我正在尝试使用python调用我的一项服务。由于某些原因,响应看起来有所不同:
卷曲命令:
curl -X POST --header "Accept: application/json" --header "Content-Type: text/plain" -d 'Machine Learning is my favorite field' http://localhost:30086/cs/tokenizer?lemmatizeTokens=true&useStrictDomainFiltering=false
Python代码:
headers = { 'Content-Type': 'text/plain', 'Accept': 'application/json'}
params = {'lemmatizeTokens': str(true).lower(), 'useStrictDomainFiltering': str(false).lower()}
url = 'http://localhost:30086/cs/tokenizer'
articleBody = 'Machine Learning is my favorite field'
data = {'articleBody': articleBody}
print(articleBody)
print(data)
r = requests.post(url, data = data, headers = headers, params=params)
if r.status_code == 200:
print(r.text)
return r.json(), 200
else:
return 'Unknown error occurred while processing tokens', 500
它们应该返回完全相同的输出,但是curl命令返回: {“ field”:1,“ machine_learning”:1,“ favorite”:1}
并且python代码返回: {“ field”:1,“ learn”:1,“ machine”:1,“ favorite”:1}
CURL输出正确,因此两者之间的调用是否有区别?似乎是输入在python代码上逐字解析。
谢谢。
答案 0 :(得分:1)
CURL请求在发送数据articleBody
时不使用键名Machine Learning is my favorite field
。