Skip to content

Strip port from strip_protocol_from_uri #44034

@ColinBe95

Description

@ColinBe95

Is your feature request related to a problem? Please describe.
I noticed a discrepancy in .net asb sdk and python sdk when it comes to parsing the fully_qualified_namespace. Half of my team is developing in .net and we get the namespace url in the following format:

https://<myservicebus>.servicebus.windows.net:443/

i.e. it ends with the port :443/. Connecting to it like:

from azure.identity.aio import DefaultAzureCredential
from azure.servicebus.aio import ServiceBusClient

client = ServiceBusClient(
    fully_qualified_namespace="myservicebus.servicebus.windows.net:443/",
    credential=DefaultAzureCredential(),
)
rec=client.get_queue_receiver("myqueue")
msgs=await rec.receive_messages(max_wait_time=1)

Results in an error:

azure.servicebus.exceptions.ServiceBusAuthenticationError: Service Bus has encountered an error. Error condition: amqp:client-error.

Whereas connecting without port, i.e.:

client = ServiceBusClient(
    fully_qualified_namespace="myservicebus.servicebus.windows.net",
    credential=DefaultAzureCredential(),
)
rec=client.get_queue_receiver("myqueue")
msgs=await rec.receive_messages(max_wait_time=1)

Worked as expected. It was not immediately clear to me why, especially because it worked for my .net colleagues.
Describe the solution you'd like
In azure.servicebus._common.utils I'd prefer to see something like:

def parse_namespace_from_uri(uri: str) -> str:
    """Removes the protocol (e.g. http:// or sb://) and port (e.g. :443/) from a URI, such as the FQDN.
    :param str uri: The URI to modify.
    :return: The URI without the protocol.
    :rtype: str
    """
    left_slash_pos = uri.find("//")
    if left_slash_pos != -1:
        uri = uri[left_slash_pos + 2 :]
    colon_pos = uri.find(":")
    if colon_pos != -1:
        uri = uri[colon_pos:]
    return uri

Describe alternatives you've considered
Removing port manually works fine.
Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ClientThis issue points to a problem in the data-plane of the library.Service AttentionWorkflow: This issue is responsible by Azure service team.Service Buscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions