如何使用用户名密码连接 coreNLP 服务器?
How to connect with coreNLP server with username password?
我在 Google App Engine 中创建了 coreNLP 服务器,并使用以下属性在其中提供了用户名和密码:-port **** -username user -密码pass.
从Python开始,我知道在属性中传递用户名和密码。
首先,我使用以下函数创建 NLP 对象并传递 URL:
sNLP = StanfordCoreNLP(serverurl)
然后我调用 annotate with data 和 属性 ,我的用户名和密码在道具中。
props: {
"annotators": "pos,sentiment",
"pipelineLanguage": "en",
"outputFormat": "json",
"username": "**user**",
"password": "***pass***",
"maxCharLength": -1
}
sNLP.annotate(data, props)
在提供身份验证之前它工作正常,但在那之后我没有从服务器收到任何响应。
那么我应该在创建 sNLP 对象时传递用户名和密码吗?如果是那么如何?我还没有找到与此相关的任何文档。
这个问题的解决方案很快就会出现在我们的 Python 代码的下一个版本中,虽然它不在当前版本中,但应该很快就会出现。
pip install stanfordnlp
回购在这里:https://github.com/stanfordnlp/stanfordnlp
如果你克隆它并检查 dev
和 运行 pip install -e .
你可以获得最新的 dev
分支代码。
示例:
from stanfordnlp.server import CoreNLPClient
with CoreNLPClient(annotators="tokenize,ssplit,pos", memory="4G", server_id='my_server_id', username='user-1234', password='1234') as client:
ann = client.annotate('Hello World!', output_format='text', username='user-1234', password='1234')
print(ann)
如果您想尝试其他解决方案,请注意当使用 requests
库发出 POST 请求时,此代码将 auth
设置为 requests.auth.HTTPBasicAuth(username, password)
。
我在 Google App Engine 中创建了 coreNLP 服务器,并使用以下属性在其中提供了用户名和密码:-port **** -username user -密码pass.
从Python开始,我知道在属性中传递用户名和密码。
首先,我使用以下函数创建 NLP 对象并传递 URL:
sNLP = StanfordCoreNLP(serverurl)
然后我调用 annotate with data 和 属性 ,我的用户名和密码在道具中。
props: {
"annotators": "pos,sentiment",
"pipelineLanguage": "en",
"outputFormat": "json",
"username": "**user**",
"password": "***pass***",
"maxCharLength": -1
}
sNLP.annotate(data, props)
在提供身份验证之前它工作正常,但在那之后我没有从服务器收到任何响应。
那么我应该在创建 sNLP 对象时传递用户名和密码吗?如果是那么如何?我还没有找到与此相关的任何文档。
这个问题的解决方案很快就会出现在我们的 Python 代码的下一个版本中,虽然它不在当前版本中,但应该很快就会出现。
pip install stanfordnlp
回购在这里:https://github.com/stanfordnlp/stanfordnlp
如果你克隆它并检查 dev
和 运行 pip install -e .
你可以获得最新的 dev
分支代码。
示例:
from stanfordnlp.server import CoreNLPClient
with CoreNLPClient(annotators="tokenize,ssplit,pos", memory="4G", server_id='my_server_id', username='user-1234', password='1234') as client:
ann = client.annotate('Hello World!', output_format='text', username='user-1234', password='1234')
print(ann)
如果您想尝试其他解决方案,请注意当使用 requests
库发出 POST 请求时,此代码将 auth
设置为 requests.auth.HTTPBasicAuth(username, password)
。