我想通过我的Python脚本向Netsuite发布一个日志条目。我正在用zeep和SuiteTalk交谈。
我是Netsuite的新手,也是肥皂的新手。在internet示例中,我使用以下代码通过Python脚本添加了一个测试客户:
def make_app_info(client):
AppInfo = client.get_type('ns4:ApplicationInfo')
app_info = AppInfo(applicationId=NS_APPID)
return app_info
def make_passport(client):
RecordRef = client.get_type('ns0:RecordRef')
Passport = client.get_type('ns0:Passport')
role = RecordRef(internalId=NS_ROLE)
return Passport(email=NS_EMAIL,
password=NS_PASSWORD,
account=NS_ACCOUNT,
role=role)
def login_client():
client = Client(WSDL_URL)
login = client.service.login(passport=make_passport(client), _soapheaders={'applicationInfo': make_app_info(client)})
return client我使用的WSDL_URL是0/netsuite.wsdl
使用上面的客户端,下面的代码添加了客户:
def add_customer():
client = login_client()
Customer = client.get_type('ns13:Customer')
customer = Customer(
lastName='Prasad',
firstName='Vikas',
email='vikasprasad@example.com',
companyName='Test Company'
)
client.service.add(customer)
add_customer()上面的代码成功地将Customer添加到Netsuite帐户,我可以在webapp的列表中看到它。继续上面的示例,我编写了下面的代码来添加JournalEntry
def get_record_by_type(client, type, internal_id):
RecordRef = client.get_type('ns0:RecordRef')
record = RecordRef(internalId=internal_id, type=type)
response = client.service.get(record,
_soapheaders={
'applicationInfo': make_app_info(client),
'passport': make_passport(client),
}
)
r = response.body.readResponse
if r.status.isSuccess:
return r.record
def add_journal_entry():
client = login_client()
# get subsidiary by internal id
subsidiary = get_record_by_type(client, 'subsidiary', '1')
print(subsidiary) # This prints a valid subsidiary having internal id 1
# create two journal entry lines
JournalEntryLine = client.get_type('ns31:JournalEntryLine')
credit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '1'), credit=100)
debit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '2'), debit=100)
print(credit_line) # This prints credit_line with a valid account having internal id 1
print(debit_line) # This prints debit_line with a valid account having internal id 2
JournalEntryLineList = client.get_type('ns31:JournalEntryLineList')
journal_entry_line_list = JournalEntryLineList(line=[credit_line, debit_line])
JournalEntry = client.get_type('ns31:JournalEntry')
journal_entry = JournalEntry(subsidiary=subsidiary, lineList=journal_entry_line_list)
client.service.add(journal_entry, _soapheaders={'passport': make_passport(client),
'applicationInfo': make_app_info(client)}) # Fails on this line.
add_journal_entry()这在调用client.service.add(...)时失败,错误如下:
{urn:core_2017_2.platform.webservices.netsuite.com}name,{urn:accounting_2017_2.lists.webservices.netsuite.com}name zeep.exceptions.Fault: org.xml.sax.SAXException: Expected zeep.exceptions.Fault
我确信这在SOAP世界中是很愚蠢的,但我不知道该向哪个方向进行调试。为什么预期的和发现的有区别?我没有提到任何特定的名称空间。它只是WSDL v2017_2_0,所有的client.get_type()调用都是在此基础上进行的。这个错误从何而来?
曾在Netsuite用户组问过同样的问题:https://usergroup.netsuite.com/users/forum/platform-areas/web-services-suitetalk/434717-netsuite-namespace-conflict#post434717
UPDATE:基于@Justin的答案的发现,与其从Suitetalk获取subsidiary和accounts,然后将它们添加到请求中,我可以直接告诉Suitetalk type和internalId使用RecordRef和Suitetalk将理解subsidiary和account所使用的内容。
也就是说,subsidiary = get_record_by_type(client, 'subsidiary', '1')可以更改为subsidiary = RecordRef(internalId='1', type='subsidiary')
类似的
credit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '1'), credit=100)
debit_line = JournalEntryLine(account=get_record_by_type(client, 'account', '2'), debit=100)可以更改为
credit_line = JournalEntryLine(account=RecordRef(internalId='1', type='account'), credit=100)
debit_line = JournalEntryLine(account=RecordRef(internalId='2', type='account'), debit=100)发布于 2018-05-25 15:21:45
我认为可能是您的get_account()返回了一个Account,但是JournalEntryLine.account应该是一个RecordRef (实际上,get_subsidiary()的问题也是一样的)
https://stackoverflow.com/questions/50461876
复制相似问题