gpt4 book ai didi

python - 如何将 gRPC 服务器/客户端部署到 heroku?

转载 作者:太空狗 更新时间:2023-10-30 01:19:19 27 4
gpt4 key购买 nike

我将我的 python gRPC 服务器部署到 Heroku,想知道如何使用本地 Python 客户端测试它。

server.py

def serve():
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
icp_pb2_grpc.add_MyServicer_to_server(MyServicer(), server)

server_port = os.environ.get('PORT', 50051)
server.add_insecure_port('[::]:'+ str(server_port))
server.start()
print("==== SERVER RUNNING =====")
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except KeyboardInterrupt:
server.stop(0)

if __name__ == '__main__':
serve()

client.py

def run():
# Is the channel url correct?
channel = grpc.insecure_channel('https://www.HEROKUURL.com:50051')
stub = my_grpc.MyStub(channel)
file = _get_file_content()
response = stub.Predict(icp_pb2.MyRequest(file_content=file))
print("received: " + response.results)

我在我的电脑上使用客户端,但没有收到来自服务器的任何响应。如果在本地启动,我能够成功地与服务器通信。我做错了什么?

最佳答案

Heroku does not support HTTP 2。另一方面,GRPC 使用基于 http/2 的传输。我认为这就是为什么您可以在本地连接它而不是从 Heroku 连接它的原因。

关于python - 如何将 gRPC 服务器/客户端部署到 heroku?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47682427/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com