我正在尝试拨打外部53 | SSRS44 | Active | 2018-08-20 10:10:10
53 | SSRS44 | Consumed | 2018-08-20 10:10:10
53 | SSRS44 | Consumed | 2018-08-20 10:10:10
从Google Cloud Natural Language API
任务(使用Celery
包)中获取。问题在于对API的调用永远不会返回(挂起):
google-cloud-python
我试图解决的问题:
@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
模块调用API。芹菜可以很好地工作,因此问题必须出在requests
内。关于如何调试或解决此问题的任何想法?
答案 0 :(得分:0)
由于问题似乎出在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())