我正在尝试从一个Google Cloud Natural Language API任务中调用一个外部Celery (使用google-cloud-python包)。问题是对API的调用永远不会返回(挂起):
@celery.task()
def get_entities_async():
return get_entities()
def get_entities():
gcloud_client = LanguageServiceClient()
doc = types.Document(content='This is a test.', language='en', type='PLAIN_TEXT')
res = gcloud_client.analyze_entities(document=doc) # This call never returns
print('Call successful!') # (This never gets printed)
return res我想解决的问题是:
get_entities()。这个很好用。timeout=1和retry=False。它还挂着。requests模块调用API。这在芹菜中很好,所以问题必须是在LanguageServiceClient中。对于如何调试或解决这个问题,有什么想法吗?
发布于 2018-09-10 09:31:24
由于问题似乎在LanguageServiceClient中,所以我使用requests模块来调用celery工作者内部的API:
import requests
# Temporary solution to call the Natural Language API
def get_entities():
doc = {'type': 1, 'language': 'en', 'content': 'This is a test.'}
d = {'document': doc, 'encodingType': 'UTF32'}
url = 'https://language.googleapis.com/v1beta2/documents:analyzeEntities?key=' + API_KEY
return requests.post(url, json=d, timeout=10.0).json())https://stackoverflow.com/questions/51964541
复制相似问题