urlparse是用于此的正确模块,还是还有其他功能?
>>> o = urlparse.urlparse('"User Name" <sips:+msisdn@domain?Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit>', scheme='sips')
>>> print o
ParseResult(scheme='sips', netloc='', path='"User Name" <sips:+msisdn@domain', params='', query='Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit>', fragment='')
>>>
我希望在netloc或path上有msisdn @ domain,但是path中的值有点奇怪.
解决方法:
您不是在解析SIPS URI,而是在解析记录地址(AOR).如果从AOR中提取URI,则会得到:
>>> o = urlparse.urlparse('sips:+msisdn@domain?Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit')
>>> print o
ParseResult(scheme='sips', netloc='', path='+msisdn@domain', params='', query='Accept-Contact=+sip.instance="<urn:uuid:2e7671fd-31dd-1393-dkd6-835fe09f314f>";require;explicit', fragment='')
根据RFC 3986,SIPS URI的userinfo @ host部分应放入路径组件,因此此处的结果正确.