首页 > 解决方案 > 当我已经在虚拟环境中使用 django 运行 API 端点时,如何部署 tabpy 代码?

问题描述

我正在尝试在 python 中使用 django 并在 R 中使用 restrserve 创建一个 api 端点,并在 tabpy 中部署以下代码以与 tableau 连接,我正面临这个错误。有人可以推荐任何解决方案。

错误信息:

ConnectionError: HTTPConnectionPool(host='127.0.0.1', port=9004): 最大重试次数超过 url: /endpoints (由 NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000016136C007C8>: 未能建立新连接: [ WinError 10061] 由于目标机器主动拒绝,无法建立连接'))

代码:

import tabpy_client
import requests
client = tabpy_client.Client('http://127.0.0.1:9004')

def external_services_say_hello(message, service):
    if service == 'PYTHON':
        r = requests.post('http://127.0.0.1:8000/', data ={'message': message})
    elif service == 'R':
        r = requests.post('http://localhost:8080/hello', data = {'message': message,})
 
    serviceResult = r.json()
    return serviceResult['result']

client.deploy('external_services_say_hello', external_services_say_hello, 'Make Python or R say Hello or anything you want.', override = True)
print('*** Model deployed successfully ***')

提前致谢!

标签: python

解决方案


推荐阅读