我想在 Websocket 客户端连接到 AWS lambda 和 API 网关上的服务器时向其发送消息。目前,我使用 wscat 作为客户端。由于当我连接到服务器时,wscat 控制台上未显示响应“已连接”,因此我添加了 post_to_connection 来向客户端发送消息“hello world”。但是,它会引发 GoneException。
调用 PostToConnection 操作时发生错误 (GoneException)
如何解决这个问题并在连接到服务器时向 wscat 发送一些消息?
我的Python代码如下。我使用Python 3.8.5。
import os
import boto3
import botocore
dynamodb = boto3.resource('dynamodb')
connections = dynamodb.Table(os.environ['TABLE_NAME'])
def lambda_handler(event, context):
domain_name = event.get('requestContext',{}).get('domainName')
stage = event.get('requestContext',{}).get('stage')
connection_id = event.get('requestContext',{}).get('connectionId')
result = connections.put_item(Item={ 'id': connection_id })
apigw_management = boto3.client('apigatewaymanagementapi',
endpoint_url=F"https://{domain_name}/{stage}")
ret = "hello world";
try:
_ = apigw_management.post_to_connection(ConnectionId=connection_id,
Data=ret)
except botocore.exceptions.ClientError as e:
print(e);
return { 'statusCode': 500,
'body': 'something went wrong' …Run Code Online (Sandbox Code Playgroud) 我想要以下平面图 g 的对偶图。
from networkx.generators.lattice import hexagonal_lattice_graph;
g = hexagonal_lattice_graph(2,3);
Run Code Online (Sandbox Code Playgroud)
网络 x 有返回对偶图的函数吗?我什至不知道如何获得 g 的面孔。
我想使用 sagemath 的立方体组。我做了如下。
python -m pip install sagemath
Run Code Online (Sandbox Code Playgroud)
进而
import sagemath.cubegroup;
Run Code Online (Sandbox Code Playgroud)
在Python脚本中。但我收到以下错误。
ImportError: No module named cubegroup
Run Code Online (Sandbox Code Playgroud)
我尝试了 python2 和 python3 但都不起作用。我也尝试过用 sage 代替 sagemath,但也没有用。
如何在Python上使用sagemath和cubegroup?