Python 如何使用GraphSON v2而不是v3?

Python 如何使用GraphSON v2而不是v3?,python,azure,azure-cosmosdb,graphson,Python,Azure,Azure Cosmosdb,Graphson,我正在尝试用python运行一段代码,它使用来自Microsoft Azure的Cosmos DB。我目前正在使用gremlinpython 3.2.6和最新版本的Cosmos(microsoft azure上的默认版本),但两者之间似乎存在一些兼容性问题 当我运行我的代码时,我得到以下错误 GremlinServerError: 498: ActivityId : 5c05bb15-3aa1-41b8-9c10-ab3015152eab ExceptionType : GraphMalfo

我正在尝试用python运行一段代码,它使用来自Microsoft Azure的Cosmos DB。我目前正在使用gremlinpython 3.2.6和最新版本的Cosmos(microsoft azure上的默认版本),但两者之间似乎存在一些兼容性问题

当我运行我的代码时,我得到以下错误

GremlinServerError: 498: 

ActivityId : 5c05bb15-3aa1-41b8-9c10-ab3015152eab
ExceptionType : GraphMalformedException
ExceptionMessage :
    Gremlin Malformed Request: GraphSON v3 IO is not supported.
    GremlinRequestId : 5c05bb15-3aa1-41b8-9c10-ab3015152eab
    Context : global
    GraphInterOpStatusCode : MalformedRequest
    HResult : 0x80131500

我已经读到,我应该尝试使用GraphSON v2而不是V3,但不知道如何使用,有人能帮忙吗?

欢迎来到这个社区。您只需要确保使用GraphSON v2的模式,因为它是Azure Cosmos DB支持的版本。检查您正在使用的json,并确保遵循支持的模式。您在中有一些示例。

欢迎来到这个社区。您只需要确保使用GraphSON v2的模式,因为它是Azure Cosmos DB支持的版本。检查您正在使用的json,并确保遵循支持的模式。您在中有一些示例。

默认情况下,gremlin_python使用
图形序列化RSV3d0
,因此在创建客户端时必须显式传递
图形序列化RSV2d0

from gremlin_python.driver import client, serializer

client.Client(
    message_serializer=serializer.GraphSONSerializersV2d0(),
    password="...",
    traversal_source='g',
    url='wss://...:443/',
    username="/dbs/.../colls/...",
)

默认情况下,gremlin_python使用
GraphSONSerializersV3d0
,因此在创建客户端时必须显式传递
GraphSONSerializersV2d0

from gremlin_python.driver import client, serializer

client.Client(
    message_serializer=serializer.GraphSONSerializersV2d0(),
    password="...",
    traversal_source='g',
    url='wss://...:443/',
    username="/dbs/.../colls/...",
)

在创建客户端时,将其作为
mime
类型提供

var client = new GremlinClient(gremlinServer:gremlinServer,mimeType:GremlinClient.GraphSON2MimeType)

在创建客户端时,将其作为
mime
类型提供

var client = new GremlinClient(gremlinServer:gremlinServer,mimeType:GremlinClient.GraphSON2MimeType)
使用C#,如果将连接配置放在Startup.cs中,则可以如下配置:

services.AddSingleton<GremlinClient>(
            (serviceProvider) =>
            {
                var gremlinServer = new GremlinServer(
                    hostname: "<account>.gremlin.cosmosdb.azure.com",
                    port: <port>,
                    enableSsl: true,
                    username: "/dbs/<db>/colls/<collection>",
                    password: ""
                    );
                var connectionPoolSettings = new ConnectionPoolSettings
                {
                    MaxInProcessPerConnection = 32,
                    PoolSize = 4,
                    ReconnectionAttempts = 3,
                    ReconnectionBaseDelay = TimeSpan.FromSeconds(1),
                };
                var mimeType = "application/vnd.gremlin-v2.0+json";
                return new GremlinClient
                (
                    gremlinServer: gremlinServer,
                    graphSONReader: new GraphSON2Reader(),
                    graphSONWriter: new GraphSON2Writer(),
                    mimeType: mimeType,
                    connectionPoolSettings: connectionPoolSettings
                );
            }
        );
services.AddSingleton(
(服务提供商)=>
{
var gremlinServer=新的gremlinServer(
主机名:“.gremlin.cosmosdb.azure.com”,
端口:,
enableSsl:true,
用户名:“/dbs//colls/”,
密码:“
);
var connectionPoolSettings=新的connectionPoolSettings
{
MaxInProcessPerConnection=32,
池大小=4,
重新连接尝试次数=3,
重新连接BaseDelay=从秒开始的时间跨度(1),
};
var mimeType=“application/vnd.gremlin-v2.0+json”;
返回新的GremlinClient
(
gremlinServer:gremlinServer,
graphSONReader:新的GraphSON2Reader(),
graphSONWriter:新的GraphSON2Writer(),
mimeType:mimeType,
connectionPoolSettings:connectionPoolSettings
);
}
);
否则,应使用以下读写器和mimeType创建gremlin客户端:

var mimeType = "application/vnd.gremlin-v2.0+json";
var client = new GremlinClient
(
      gremlinServer: <your server>,
      graphSONReader: new GraphSON2Reader(),
      graphSONWriter: new GraphSON2Writer(),
      mimeType: mimeType,
      connectionPoolSettings: <your connection pool>
 );
var mimeType=“application/vnd.gremlin-v2.0+json”;
var client=新的GremlinClient
(
gremlinServer:,
graphSONReader:新的GraphSON2Reader(),
graphSONWriter:新的GraphSON2Writer(),
mimeType:mimeType,
连接池设置:
);
使用C#,如果将连接配置放在Startup.cs中,则可以如下配置:

services.AddSingleton<GremlinClient>(
            (serviceProvider) =>
            {
                var gremlinServer = new GremlinServer(
                    hostname: "<account>.gremlin.cosmosdb.azure.com",
                    port: <port>,
                    enableSsl: true,
                    username: "/dbs/<db>/colls/<collection>",
                    password: ""
                    );
                var connectionPoolSettings = new ConnectionPoolSettings
                {
                    MaxInProcessPerConnection = 32,
                    PoolSize = 4,
                    ReconnectionAttempts = 3,
                    ReconnectionBaseDelay = TimeSpan.FromSeconds(1),
                };
                var mimeType = "application/vnd.gremlin-v2.0+json";
                return new GremlinClient
                (
                    gremlinServer: gremlinServer,
                    graphSONReader: new GraphSON2Reader(),
                    graphSONWriter: new GraphSON2Writer(),
                    mimeType: mimeType,
                    connectionPoolSettings: connectionPoolSettings
                );
            }
        );
services.AddSingleton(
(服务提供商)=>
{
var gremlinServer=新的gremlinServer(
主机名:“.gremlin.cosmosdb.azure.com”,
端口:,
enableSsl:true,
用户名:“/dbs//colls/”,
密码:“
);
var connectionPoolSettings=新的connectionPoolSettings
{
MaxInProcessPerConnection=32,
池大小=4,
重新连接尝试次数=3,
重新连接BaseDelay=从秒开始的时间跨度(1),
};
var mimeType=“application/vnd.gremlin-v2.0+json”;
返回新的GremlinClient
(
gremlinServer:gremlinServer,
graphSONReader:新的GraphSON2Reader(),
graphSONWriter:新的GraphSON2Writer(),
mimeType:mimeType,
connectionPoolSettings:connectionPoolSettings
);
}
);
否则,应使用以下读写器和mimeType创建gremlin客户端:

var mimeType = "application/vnd.gremlin-v2.0+json";
var client = new GremlinClient
(
      gremlinServer: <your server>,
      graphSONReader: new GraphSON2Reader(),
      graphSONWriter: new GraphSON2Writer(),
      mimeType: mimeType,
      connectionPoolSettings: <your connection pool>
 );
var mimeType=“application/vnd.gremlin-v2.0+json”;
var client=新的GremlinClient
(
gremlinServer:,
graphSONReader:新的GraphSON2Reader(),
graphSONWriter:新的GraphSON2Writer(),
mimeType:mimeType,
连接池设置:
);

谢谢,我还有一个问题要问。创建新图形时,我得到以下错误:
Gremlin查询执行错误:无法添加分区键属性值为“null”的顶点
我的上一个图形具有以下分区键:
/\u partitionKey
但该键似乎不适用于新图形?添加顶点时需要指定分区键-问题报告并解释了这没有帮助-您如何设置它以确保使用GraphsonV2和GremlinPython?这个链接没有任何解释。尽管这是公认的答案,但对我没有帮助。我设法弄明白了如何使用
GraphSON v2
,请看我的答案:谢谢,我还有一个问题要问。创建新图形时,我得到以下错误:
Gremlin查询执行错误:无法添加分区键属性值为“null”的顶点
我的上一个图形具有以下分区键:
/\u partitionKey
但该键似乎不适用于新图形?添加顶点时需要指定分区键-问题报告并解释了这没有帮助-您如何设置它以确保使用GraphsonV2和GremlinPython?这个链接没有任何解释。即使这是公认的答案,也没有帮助