连接烧瓶recastai阿比
我使用recastai写FB机器人,我下面这个样本https://recast.ai/docs/api-reference/#request-text,我写了这个代码来分析文本连接烧瓶recastai阿比
from flask import Flask import recastai
app = Flask(__name__)
@app.route('/')
def home():
request = recastai.Request('TOKEN')
response = request.analyse_text('Hello')
return 'hello'
输出页面显示“内部服务器错误”和错误日志显示导入错误,但它仅出现后,我加入响应行
2017-12-03 05:41:16,767: ***************************************************
2017-12-03 06:48:14,534: Error running WSGI application
2017-12-03 06:48:14,555: requests.exceptions.ProxyError: HTTPSConnectionPool(host='api.recast.ai', port=443): Max retries exceeded with url: /v2/request (Caused by ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 403 Forbidden',)))
2017-12-03 06:48:14,555: File "/var/www/tarekhassan_pythonanywhere_com_wsgi.py", line 16, in <module>
2017-12-03 06:48:14,556: from hello import app as application
2017-12-03 06:48:14,556:
2017-12-03 06:48:14,556: File "/home/tarekhassan/bot/hello.py", line 7, in <module>
2017-12-03 06:48:14,556: def home():
2017-12-03 06:48:14,556:
2017-12-03 06:48:14,556: File "/home/tarekhassan/.local/lib/python3.5/site-packages/recastai/apis/request/analyse.py", line 27, in analyse_text
2017-12-03 06:48:14,556: headers={'Authorization': "Token {}".format(token)}
2017-12-03 06:48:14,556:
2017-12-03 06:48:14,556: File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 111, in post
2017-12-03 06:48:14,557: return request('post', url, data=data, json=json, **kwargs)
2017-12-03 06:48:14,557:
2017-12-03 06:48:14,557: File "/usr/local/lib/python3.5/dist-packages/requests/api.py", line 57, in request
2017-12-03 06:48:14,557: return session.request(method=method, url=url, **kwargs)
2017-12-03 06:48:14,557:
2017-12-03 06:48:14,557: File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 475, in request
2017-12-03 06:48:14,557: resp = self.send(prep, **send_kwargs)
2017-12-03 06:48:14,558:
2017-12-03 06:48:14,558: File "/usr/local/lib/python3.5/dist-packages/requests/sessions.py", line 585, in send
2017-12-03 06:48:14,558: r = adapter.send(request, **kwargs)
2017-12-03 06:48:14,558:
2017-12-03 06:48:14,558: File "/usr/local/lib/python3.5/dist-packages/requests/adapters.py", line 465, in send
2017-12-03 06:48:14,558: raise ProxyError(e, request=request)
2017-12-03 06:48:14,559: ***************************************************
2017-12-03 06:48:14,559: If you're seeing an import error and don't know why,
2017-12-03 06:48:14,559: we have a dedicated help page to help you debug:
2017-12-03 06:48:14,559: https://help.pythonanywhere.com/pages/DebuggingImportError/
回答:
实际上,你可以用SDK设置代理,当你初始化客户端:
# coding: utf-8 from .apis import Connect, Request, Build
class Client(): def __init__(self, token=None, language=None, proxy=None):
for api in [Connect, Request, Build]:
setattr(self, api.__name__.lower(), api(token=token, language=language, proxy=proxy))
全部文件可以在这个网址上找到:https://github.com/RecastAI/SDK-python/blob/master/recastai/client.py
以上是 连接烧瓶recastai阿比 的全部内容, 来源链接: utcz.com/qa/259680.html