为什么我没有从我的asterisk服务器得到以下扭曲SIP python代码的响应

为什么我没有从我的asterisk服务器得到以下扭曲SIP python代码的响应,python,localhost,twisted,asterisk,sip,Python,Localhost,Twisted,Asterisk,Sip,使用此处找到的代码 我已尝试发送我的本地(127.0.0.1)星号服务器简单SIP选项检查 From twisted.protocols import sip From twisted.internet import defer, reactor class Client(sip.Base): def __init__(self): sip.Base.__init__(self) self.received = [] self.defe

使用此处找到的代码

我已尝试发送我的本地(127.0.0.1)星号服务器简单SIP选项检查

From twisted.protocols import sip
From twisted.internet import defer, reactor

class Client(sip.Base):

    def __init__(self):
        sip.Base.__init__(self)
        self.received = []
        self.deferred = defer.Deferred()

    def handle_response(self, response, addr):
        self.received.append(response)
        self.deferred.callback(self.received)

class OptionsC():

    def setup(self):
        self.client = Client()
        self.clientPort = reactor.listenUDP(
            5062, self.client, interface="127.0.1.1")

    def testRegisterOPT(self):
        p = self.clientPort.getHost().port
        r = sip.Request("OPTIONS", "sip:127.0.0.1")
        r.addHeader("via", sip.Via("127.0.1.1", port=5062, rport=5062, branch="test123").toString())
        r.addHeader("to", "<sip:joe@127.0.1.1>")
        r.addHeader("From", "<sip:joe@127.0.1.1>")
        r.addHeader("Call-ID", "<1opt@127.0.1.1>")
        r.addHeader("CSeq", "1 OPTIONS")
        r.addHeader("contact", "<sip:joe@127.0.1.1:5062;transport=UDP>")
        r.addHeader("Accept", "application/sdp")
        r.addHeader("Content-Length", "0")
        print(r.toString())
        self.client.sendMessage(
            sip.URL(host="127.0.0.1", port=5060), r)
        d = self.client.deferred

        def check(received):
            self.assertEqual(len(received), 1)
            r = received[0]
            print(r)
            print(r.code)
            print(dir(r))
            self.assertEqual(r.code, 200)
        d.addCallback(check)
        return d 

opc = OptionsC()
opc.setup()
res = opc.testRegisterOPT()
print("test")
在星号上,我可以看到消息到达。
但asterisk从来不会发送一个200 ok、错误或任何对我理解代码错误有用的响应

*CLI> sip set debug on
SIP Debugging enabled

<--- SIP read from UDP:127.0.1.1:5062 --->
OPTIONS sip:127.0.0.1 SIP/2.0
Via: SIP/2.0/UDP 127.0.1.1:5062;branch=test123;rport=5062
To: <sip:joe@127.0.1.1>
From: <sip:joe@127.0.1.1>
Call-ID: <1opt@127.0.1.1>
CSeq: 1 OPTIONS
Contact: <sip:joe@127.0.1.1:5062;transport=UDP>
Accept: application/sdp
Content-Length: 0

<------------->
--- (9 headers 0 lines) ---
*CLI>sip设置调试打开
已启用SIP调试
选项sip:127.0.0.1 sip/2.0
Via:SIP/2.0/UDP 127.0.1.1:5062;分支=test123;rport=5062
致:
发件人:
呼叫ID:
CSeq:1个选项
联系人:
接受:应用程序/sdp
内容长度:0
---(9个标题0行)---
将此命令与执行类似操作的以下命令进行比较

$ sipp -sf ./options.xml -m 1  -max_non_invite_retrans 1 127.0.0.1:5060
Resolving remote host '127.0.0.1'... Done.
$ cat ./options.xml 
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">

<scenario name="Options">

  <send retrans="500" start_rtd="opt-timer">
    <![CDATA[

      OPTIONS sip:[remote_ip] SIP/2.0
      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
      Max-Forwards: 70
      To: <sip:[service]@[remote_ip]>
      From: <sip:[service]@[remote_ip]>;tag=[call_number]
      Call-ID: [call_id]
      CSeq: [cseq] OPTIONS
      Contact: <sip:[service]@[local_ip]:[local_port];transport=[transport]>
      Accept: application/sdp
      Content-Length: 0

    ]]>
  </send>

  <recv response="200" rrs="true" rtd="opt-timer"></recv>


  <!-- definition of the response time repartition table (unit is ms)   -->
  <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>

  <!-- definition of the call length repartition table (unit is ms)     -->
  <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>

</scenario>
$sipp-sf./options.xml-m1-max_non_invite_retrans 1127.0.0.1:5060
正在解析远程主机“127.0.0.1”。。。完成。
$cat./options.xml
发件人:;标签=[呼叫号码]
呼叫ID:[呼叫ID]
CSeq:[CSeq]选项
联系人:
接受:应用程序/sdp
内容长度:0
]]>
哪个星号正确地生成对的响应

<--- SIP read from UDP:127.0.0.1:5061 --->
OPTIONS sip:127.0.0.1 SIP/2.0
Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-19903-1-0
Max-Forwards: 70
To: <sip:service@127.0.0.1>
From: <sip:service@127.0.0.1>;tag=1
Call-ID: 1-19903@127.0.1.1
CSeq: 1 OPTIONS
Contact: <sip:service@127.0.1.1:5061;transport=UDP>
Accept: application/sdp
Content-Length: 0

<------------->
--- (10 headers 0 lines) ---
Sending to 127.0.0.1:5061 (NAT)
Looking for s in public (domain 127.0.0.1)

<--- Transmitting (NAT) to 127.0.0.1:5061 --->
SIP/2.0 200 OK
Via: SIP/2.0/UDP 127.0.1.1:5061;branch=z9hG4bK-19903-1-0;received=127.0.0.1;rport=5061
From: <sip:service@127.0.0.1>;tag=1
To: <sip:service@127.0.0.1>;tag=as6e9328e8
Call-ID: 1-19903@127.0.1.1
CSeq: 1 OPTIONS
Server: Asterisk PBX 13.10.0~dfsg-1ubuntu2
Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
Supported: replaces, timer
Contact: <sip:127.0.0.1:5060>
Accept: application/sdp
Content-Length: 0


<------------>
Scheduling destruction of SIP dialog '1-19903@127.0.1.1' in 32000 ms (Method: OPTIONS)
Really destroying SIP dialog '1-19903@127.0.1.1' Method: OPTIONS

选项sip:127.0.0.1 sip/2.0
Via:SIP/2.0/UDP 127.0.1.1:5061;分支机构=z9hG4bK-19903-1-0
最大前锋:70
致:
发件人:;标签=1
电话号码:1-19903@127.0.1.1
CSeq:1个选项
联系人:
接受:应用程序/sdp
内容长度:0
---(10个标题0行)---
发送至127.0.0.1:5061(NAT)
在公共场合寻找s(域127.0.0.1)
SIP/2.0 200正常
Via:SIP/2.0/UDP 127.0.1.1:5061;分支机构=z9hG4bK-19903-1-0;接收=127.0.0.1;rport=5061
发件人:;标签=1
致:;标签=as6e9328e8
电话号码:1-19903@127.0.1.1
CSeq:1个选项
服务器:星号PBX 13.10.0~dfsg-1ubuntu2
允许:邀请、确认、取消、选项、再见、参考、订阅、通知、信息、发布、消息
支持:替换、定时器
联系人:
接受:应用程序/sdp
内容长度:0
正在计划销毁SIP对话框“1”-19903@127.0.1.1'在32000毫秒内(方法:选项)
真的破坏了SIP对话框'1-19903@127.0.1.1"方法:选择
我能看到的是SIP正在后台做一些其他工作来初始化SIP对话框。 我认为这就是上面这个示例代码中缺少的内容。
当星号正确开始向sipp正在创建的客户端发送响应时

通过删除
r.addHeader(“CSeq”,“1选项”)

我现在得到了本地星号的回应

def testRegisterOPT(self):
    p = self.clientPort.getHost().port
    r = sip.Request("OPTIONS", "sip:127.0.0.1")
    r.addHeader("via", sip.Via("127.0.1.1", port=5062, rport=5062, branch="test123").toString())
    r.addHeader("to", "<sip:joe@127.0.1.1>")
    r.addHeader("From", "<sip:joe@127.0.1.1>")
    r.addHeader("Call-ID", "<1opt@127.0.1.1>")
    # r.addHeader("CSeq", "1 OPTIONS")
    r.addHeader("contact", "<sip:joe@127.0.1.1:5062;transport=UDP>")
    r.addHeader("Accept", "application/sdp")
    r.addHeader("Content-Length", "0")
    print(r.toString())
    self.client.sendMessage(
        sip.URL(host="127.0.0.1", port=5060), r)
    d = self.client.deferred
def testRegisterOPT(self):
    p = self.clientPort.getHost().port
    r = sip.Request("OPTIONS", "sip:127.0.0.1")
    r.addHeader("via", sip.Via("127.0.1.1", port=5062, rport=5062, branch="test123").toString())
    r.addHeader("to", "<sip:joe@127.0.1.1>")
    r.addHeader("From", "<sip:joe@127.0.1.1>")
    r.addHeader("Call-ID", "<1opt@127.0.1.1>")
    # r.addHeader("CSeq", "1 OPTIONS")
    r.addHeader("contact", "<sip:joe@127.0.1.1:5062;transport=UDP>")
    r.addHeader("Accept", "application/sdp")
    r.addHeader("Content-Length", "0")
    print(r.toString())
    self.client.sendMessage(
        sip.URL(host="127.0.0.1", port=5060), r)
    d = self.client.deferred
    <--- SIP read from UDP:127.0.0.1:46947 --->
    OPTIONS sip:127.0.0.1 SIP/2.0
    Via: SIP/2.0/UDP 127.0.0.1:5062;rport=5062
    Max-Forward: 3
    To: <sip:OptionsCheckMonitor@127.0.0.1>
    From: <sip:OptionsCheckMonitor@127.0.0.1>
    Call-ID: <1optioncheck@127.0.0.1>
    Contact: <sip:OptionsCheckMonitor@127.0.0.1;transport=UDP>
    Accept: application/sdp
    Content-Length: 0

    <------------->
    --- (9 headers 0 lines) ---
    Sending to 127.0.0.1:5062 (no NAT)
    [Jan 24 12:52:54] NOTICE[12752]: chan_sip.c:11681 copy_header: No field 'CSeq' present to copy

    <--- Transmitting (no NAT) to 127.0.0.1:5062 --->
    SIP/2.0 400 Bad Request
    Via: SIP/2.0/UDP 127.0.0.1:5062;rport=5062;received=127.0.0.1
    From: <sip:OptionsCheckMonitor@127.0.0.1>
    To: <sip:OptionsCheckMonitor@127.0.0.1>;tag=as7d34b365
    Call-ID: <1optioncheck@127.0.0.1>
    Server: Asterisk PBX 13.10.0~dfsg-1ubuntu2
    Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE
    Supported: replaces, timer
    Content-Length: 0