Azure Cosmos DB Python连接报错:GraphSON v3 IO不支持
问题描述
原本可正常运行的Python连接Azure Cosmos DB的代码,现在出现报错:gremlin_python.driver.protocol.GremlinServerError: 498
异常信息显示:Gremlin Malformed Request: GraphSON v3 IO is not supported
使用的代码如下:
client = Client( url = cosmos_db_url, traversal_source = 'g', message_serializer = GraphSONMessageSerializer(), username=cosmos_db_graph_path, password=cosmos_primary_key)
已尝试多个gremlinpython版本,问题依旧,求问该错误的原因。
错误原因
Azure Cosmos DB的Gremlin API不支持GraphSON v3,而你代码里使用的GraphSONMessageSerializer()在gremlinpython的新版本中默认采用GraphSON v3协议进行序列化,这与Cosmos DB的兼容要求冲突,导致请求被判定为格式错误。
解决方法是显式指定使用GraphSON v2版本的序列化器,修改后的代码如下:
from gremlin_python.driver.serializer import GraphSONMessageSerializer client = Client( url = cosmos_db_url, traversal_source = 'g', message_serializer = GraphSONMessageSerializer(graphson_version="2.0"), username=cosmos_db_graph_path, password=cosmos_primary_key)
内容的提问来源于stack exchange,提问作者William D'Alessandro
相关产品推荐
相关产品推荐

