首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在芹菜任务中调用永不返回

在芹菜任务中调用永不返回
EN

Stack Overflow用户
提问于 2018-08-22 10:09:39
回答 1查看 421关注 0票数 2

我正在尝试从一个Google Cloud Natural Language API任务中调用一个外部Celery (使用google-cloud-python包)。问题是对API的调用永远不会返回(挂起):

代码语言:javascript
复制
@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()。这个很好用。
  • 在API调用中添加了一个timeout=1retry=False。它还挂着。
  • 使用requests模块调用API。这在芹菜中很好,所以问题必须是在LanguageServiceClient中。

对于如何调试或解决这个问题,有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-10 09:31:24

由于问题似乎在LanguageServiceClient中,所以我使用requests模块来调用celery工作者内部的API:

代码语言:javascript
复制
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())
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51964541

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档