Python 使用spacy docker API
我正在尝试使用spacy作为API,如下所示: 安装后,测试用例工作正常:Python 使用spacy docker API,python,curl,docker,request,spacy,Python,Curl,Docker,Request,Spacy,我正在尝试使用spacy作为API,如下所示: 安装后,测试用例工作正常: curl http://localhost:5000/api --header 'content-type: application/json' --data '{"text": "This is a text that I want to be analyzed."}' -X POST 但是我想用python处理输出,所以我尝试使用请求库: import requests url = "http://loca
curl http://localhost:5000/api --header 'content-type: application/json' --data '{"text": "This is a text that I want to be analyzed."}' -X POST
但是我想用python处理输出,所以我尝试使用请求库:
import requests
url = "http://localhost:5000/api"
payload = {"text" : "This is a text that I want to be analyzed" }
headers = {"content-type": "application/json"}
res = requests.post(url, data=payload, headers=headers)
res.json()
但我得到一个输出错误:
{u'message': u'The browser (or proxy) sent a request that this server could not understand.'}
我还尝试使用以下建议:
但也不起作用。嘿,用这个docker图像
docker pull pasupulaphani/spacy-nlp
启动服务器
docker run --publish 4242:4242 -it spacy-nlp-zeromq:en
(或)手动启动
docker run -v ${PWD}:/usr/zeromq --publish 4242:4242 --entrypoint=/bin/bash -it spacy-nlp-zeromq:en
python3 /usr/zeromq/zeromq/server.py
原料药
解析
u'[{“tag”:“NN”,“text”:“hotel new york”}]'
实体
u'[{“end”:6,“start”:0,“text”:“hotels”,“type”:“},{“end”:16,“start”:10,“text”:“london”,“type”:“}”
名词块
$ zerorpc tcp://0.0.0.0:4242 nounChunks "hotels in london"
u'[{“文本”:“酒店”},{“文本”:“伦敦”}]
故障排除
检查端口是否打开
如果!nc-z0.0.0.04242 2>&1>/dev/null;然后回显“不可用”;fi能否添加用于启动docker容器的命令以及相应容器的日志?
$ zerorpc tcp://0.0.0.0:4242 parse "hotel new york"
$ zerorpc tcp://0.0.0.0:4242 entities "hotels in london"
$ zerorpc tcp://0.0.0.0:4242 nounChunks "hotels in london"