Azure架构注册表客户端库python不工作-未能建立新连接:[Erno 11001]getaddrinfo失败



我正按照本指南尝试将架构注册表与Azure EventHubs一起使用。我无法使这个指南发挥作用,也不清楚我应该使用模式注册表的哪个端点。有人能帮我做这个吗?

信息:

脚本

import os
import sys
import logging
from azure.eventhub import EventHubProducerClient, EventData
from azure.schemaregistry import SchemaRegistryClient
from azure.schemaregistry.serializer.avroserializer import SchemaRegistryAvroSerializer
from azure.identity import DefaultAzureCredential
# Create a logger for the SDK
logger = logging.getLogger('azure.schemaregistry')
logger.setLevel(logging.DEBUG)
# Configure a console output
handler = logging.StreamHandler(stream=sys.stdout)
logger.addHandler(handler)

os.environ['AZURE_TENANT_ID'] = "xxx"
os.environ['AZURE_CLIENT_ID'] = "xxx"
os.environ['AZURE_CLIENT_SECRET'] = "xxx"
credential = DefaultAzureCredential()
endpoint= "Endpoint=sb://xxx.servicebus.windows.net/"
schema_registry_client = SchemaRegistryClient(endpoint, credential, logging_enable=True, logger=logger)

schema_string = """
{"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{"name": "name", "type": "string"},
{"name": "favorite_number",  "type": ["int", "null"]},
{"name": "favorite_color", "type": ["string", "null"]}
]
}"""

schema_registry_client.register_schema("schema-test-group","schema-test-test","avro",schema_string)

错误

azure.core.exceptions.ServiceRequestError: <urllib3.connection.HTTPSConnection object at 0x000001CAE9D1CF70>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

日志

Request URL: 'https://Endpoint=sb://xxx.servicebus.windows.net/$schemagroups/schema-test-group/schemas/schema-test?api-version=REDACTED'
Request method: 'PUT'
Request headers:
'X-Schema-Type': 'REDACTED'
'Content-Type': 'application/json'
'Accept': 'application/json'
'Content-Length': '298'
'x-ms-client-request-id': 'xxx'
'User-Agent': 'azsdk-python-azureschemaregistry/1.0.0b1 Python/3.9.2 (Windows-10-10.0.19041-SP0)'
'Authorization': 'REDACTED'
A body is sent with the request

连接字符串的格式应为xxx.servicebus.windows.net

模式应该看起来像

"""{"namespace":"example.avro","type":"record","name":"User","fields":[{"name":"name","type":"string"},{"name":"favorite_number","type":["int","null"]},{"name":"favorite_color","type":["string","null"]}]}"""

(没有\n和其他字符(

检查此github问题:https://github.com/Azure/azure-sdk-for-python/issues/18219

相关内容

最新更新