我使用SIPSimpleClient SDK構建一個簡單的腳本,可以創建與其他一些SIP用戶的SIP會話。我開始複製並粘貼Hello World示例here到python腳本並執行它。我收到以下錯誤sipsimpleclient SDK session.connect()「類型錯誤:__init __()恰恰1參數(給定2)」
Placing call to sip:[email protected], press Enter to quit the program
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/twisted/internet/base.py", line 824, in runUntilCurrent
call.func(*call.args, **call.kw)
File "/usr/lib/python2.7/dist-packages/eventlib/coros.py", line 197, in _do_send
waiter.switch(result)
File "/usr/lib/python2.7/dist-packages/eventlib/api.py", line 235, in _spawn_startup
return cb(*args, **kw)
File "helloworldoriginal.py", line 38, in _NH_SIPApplicationDidStart
self.session.connect(self.callee, routes, [AudioStream(account)])
TypeError: __init__() takes exactly 1 argument (2 given)
對腳本放棄後,我建立了我自己的腳本從零開始基礎上,Hello World示例,並使用提供here的文檔。首先,創建一個TestClass對象(一個SIPApplication類的子類)。 TestClass中的init方法調用self.start(FileStorage('config')),此時SIPApplicationDidStart messgae會觸發我的_NH_SIPApplicationDidStart方法。到目前爲止,這一切都很好,而且這種方法的所有方面都按預期工作。當被調用者的DNSLookup成功時,它發送一個DNSLookupDidSucceed消息,該消息觸發_NH_DNSLookupDidSucceed方法。在這種方法中,我創建了一個新的會話對象(self.session = Session(account)),這似乎工作正常(我可以打印此對象的屬性此時)。這個問題似乎在self.session.connect(self.callee,self.routes,[AudioStream(account)])行中。這就是我在Hello World例子中得到相同錯誤的地方。您可以在文檔的第61頁上看到此連接方法及其參數。
************ START ************
SIP Application Did Start
SIP URI parse of callee OK
DNS Lookup Did Succeed
Will Call sip:[email protected]
Session Initiated
Session State: None
Session account: Account('xxxxxx')
Session Direction: None
Session Start Time: None
error: Exception occured in observer <__main__.TestClass object at 0x35329d0> while handling notification 'DNSLookupDidSucceed'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/application/notification.py", line 216, in post_notification
observer.handle_notification(notification)
File "<string>", line 1, in handle_notification
File "/usr/lib/python2.7/dist-packages/sipsimple/threading/__init__.py", line 100, in wrapper
func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/sipsimple/application.py", line 277, in handle_notification
handler(notification)
File "testcall.py", line 84, in _NH_DNSLookupDidSucceed
self.session.connect(self.callee, self.routes, [AudioStream(account)])
TypeError: __init__() takes exactly 1 argument (2 given)
DNS Lookup Did Succeed
Will Call sip:[email protected]
Session Initiated
Session State: None
Session account: Account('xxxxxx')
Session Direction: None
Session Start Time: None
error: Exception occured in observer <__main__.TestClass object at 0x35329d0> while handling notification 'DNSLookupDidSucceed'
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/application/notification.py", line 216, in post_notification
observer.handle_notification(notification)
File "<string>", line 1, in handle_notification
File "/usr/lib/python2.7/dist-packages/sipsimple/threading/__init__.py", line 100, in wrapper
func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/sipsimple/application.py", line 277, in handle_notification
handler(notification)
File "testcall.py", line 84, in _NH_DNSLookupDidSucceed
self.session.connect(self.callee, self.routes, [AudioStream(account)])
TypeError: __init__() takes exactly 1 argument (2 given)
Press "Enter" to exit.
我只是把XS放在哪裏,程序輸出我的賬戶名。我只是不明白這裏發生了什麼。有人知道他們爲什麼會發佈一個引發錯誤的示例程序嗎?或者這只是我的一個問題?如果您可以告訴我@run_in_green_thread行用於什麼或爲什麼發送DNSLookupDidSucceed消息兩次,獎勵點。 順便說一句,我通過SSH使用Ubuntu Trusty Tahr服務器。我正在爲一家公司這樣做,所以他們建立了環境。我假設所有的依賴都安裝正確,因爲我可以使用命令行中的sipclients(如sip-message和sip-audio-session)。我也瀏覽了這些sipclients的代碼(不是全部),他們似乎使用了同樣的session.connect()方法,而沒有這個問題。除官方文檔外,這個SDK似乎沒有多大幫助。 在此先感謝,並且這裏是我的腳本的代碼。
#!/usr/bin/env python
import sys
import time
from sipsimple.application import SIPApplication
from sipsimple.storage import FileStorage
from sipsimple.session import Session
from application.notification import NotificationCenter
from sipsimple.account import AccountManager
from sipsimple.lookup import DNSLookup, DNSLookupError
from sipsimple.core import SIPURI, ToHeader, SIPCoreError
from sipsimple.streams import AudioStream
from sipsimple.threading.green import run_in_green_thread
callee = "sip:[email protected]"
#callee = "sip:[email protected]"
class TestClass(SIPApplication):
def __init__(self):
SIPApplication.__init__(self)
self.session = None
self.callee = callee
self.routes = None
self.start(FileStorage('config'))
#make sure our methods are called when a notification is sent
notification_center = NotificationCenter()
notification_center.add_observer(self)
#not sure what this does. I get the same error whether it's here or not
@run_in_green_thread
#After the self.start(FileStorage('storage')) line is executed in __init__,
#a SIPApplicationDidStart message is sent, which invokes this method.
def _NH_SIPApplicationDidStart(self, notification):
print 'SIP Application Did Start'
try:#this line somehow puts the address into a usable format
self.callee = ToHeader(SIPURI.parse(self.callee))
print 'SIP URI parse of callee OK'
except Exception as e:
print 'ERROR1: %s' % e
self.stop()
try:#This line looks up the callee in the proxy
self.routes = DNSLookup().lookup_sip_proxy(self.callee.uri, ['udp']).wait()
except Exception as e:
print 'ERROR2: %s' %e
#Once a session is successfuly created, a SIPSessionDidStart message is
#sent which invokes this method
def _NH_SIPSessionDidStart(self, notification):
print 'SIP Session Did Start'
def _NH_SIPSessionDidFail(self, notification):
print 'SIP Session Did Fail'
def _NH_SIPSessionGotRingIndication(self, notification):
print 'SIP Session Got Ring Indication'
def _NH_SIPSessionWillStart(self, notification):
print 'SIP Session Will Start'
def _NH_DNSLookupDidSucceed(self, notification):
print 'DNS Lookup Did Succeed\nWill Call %s' %self.callee.uri
account = AccountManager().default_account
#These lines begin the creation of a session within the SIPApplication
self.session = Session(account)
print 'Session Initiated'
print 'Session State: %s' %self.session.state
print 'Session account: %s' %self.session.account
print 'Session Direction: %s' %self.session.direction
print 'Session Start Time: %s' %self.session.start_time
#THIS SEEMS TO BE THE PROBLEM LINE
self.session.connect(self.callee, self.routes, [AudioStream(account)])
def main():
print '\n************ START ************'
application = TestClass()
time.sleep(3)
print ('Press "Enter" to exit.')
raw_input()
application.stop()
print '************* END *************\n'
if __name__ == '__main__':
main()