简体   繁体   English

从Python中的SIP URI解析电话号码

[英]Parsing telephone number from a SIP URI in Python

Is urlparse the right module to use for this, or do we have something else? 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='')
>>> 

I expected +msisdn@domain at netloc or path , but the value in path is a bit strange. 我预期+msisdn@domainnetlocpath ,但在价值path是有点怪。

你可以看看它是如何在其他库中实现的,例如在twisted中https//github.com/twisted/twisted/blob/trunk/twisted/protocols/sip.py#L427

You're not parsing a SIPS URI, but an Address-Of-Record (AOR). 您没有解析SIPS URI,而是解析记录地址(AOR)。 If you extract the URI from the AOR, you'll get: 如果从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='')

According to RFC 3986 , the userinfo@host part of the SIPS URI should go into the path component, so the result is correct here. 根据RFC 3986 ,SIPS URI的userinfo@host部分应该进入path组件,因此这里的结果是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SIP URI变量的Python正则表达式? - Python Regular Expression for SIP URI variables? 如何将数字中的随机电话号码转换成字典中的单词,以及如何从文本中选择它并在python中进行转换? - How to convert a random telephone number from a number into words from dictionaries and how to select it from a text and convert it in python? 星号,获取要从外部python应用程序拨打的号码/ SIP - Asterisk, get number/SIP to dial from external python application Python将电话信转换为数字问题 - Python Translate Telephone Letter to Number Question 验证电话号码输入正确的Python程序 - Python program to verify telephone number entered correctly Python 3.6-如何用单词翻译电话号码 - Python 3.6 - How to translate a telephone number with words 如何从网页中提取电话号码? - How to extract the telephone number from the webpage? 如何通过编写 python 脚本从许多不同的 html 链接中提取 Email、电话、传真号码和地址? - How to extract Email, Telephone, Fax number and Address from many different html links by writing a python script? 我需要编写一个 python 程序来输入字母形式的电话号码,然后 output 以数字形式输入相应的电话号码 - I need to write a python program to enter a telephone number as letters and then output the corresponding telephone number in digits Python 3 urlib urlparse URI解析 - Python 3 urlib urlparse URI parsing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM