1

我正在编写一个 Python 应用程序,它连接到 Netsuite (WSDL),然后将数据插入表中。我正在尝试使用 zeep 连接到我们的 Netsuite 服务器,但出现此错误:

python3.6 /xxx/python-netsuite/netsuite/client.py
Traceback (most recent call last):
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/xsd/schema.py", line 565, in _get_component
return items[qname]
KeyError: <lxml.etree.QName object at 0x10e9bd850>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/xxx/python-netsuite/netsuite/client.py", line 2, in <module>
from netsuite.service import (client,
File "/xxx/python-netsuite/netsuite/service.py", line 13, in <module>
Passport = model('ns1:Passport')
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/client.py", line 263, in get_type
return self.wsdl.types.get_type(name)
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/xsd/schema.py", line 140, in get_type
return self._get_instance(qname, 'get_type', 'type')
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/xsd/schema.py", line 243, in _get_instance
raise last_exception
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/xsd/schema.py", line 239, in _get_instance
return method(qname)
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/xsd/schema.py", line 523, in get_type
return self._get_component(qname, self._types, 'type')
File "/xxx/.virtualenvs/for-netsuite/lib/python3.6/site-packages/zeep/xsd/schema.py", line 580, in _get_component
location=self._location)
zeep.exceptions.LookupError: No type 'Passport' in namespace 
urn:types.core_2017_1.platform.webservices.netsuite.com. Available types are: 

{urn:types.core_2017_1.platform.webservices.netsuite.com}RecordType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchRecordType, 
{urn:types.core_2017_1.platform.webservices.netsuite.com}GetAllRecordType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}GetCustomizationType, 
{urn:types.core_2017_1.platform.webservices.netsuite.com}InitializeType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}InitializeRefType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}InitializeAuxRefType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}DeletedRecordType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}AsyncStatusType,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchStringFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchLongFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchTextNumberFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchDoubleFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchDateFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchEnumMultiSelectFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchMultiSelectFieldOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SearchDate,
{urn:types.core_2017_1.platform.webservices.netsuite.com}DurationUnit,
{urn:types.core_2017_1.platform.webservices.netsuite.com}CalendarEventAttendeeResponse,
{urn:types.core_2017_1.platform.webservices.netsuite.com}GetSelectValueFilterOperator,
{urn:types.core_2017_1.platform.webservices.netsuite.com}SignatureAlgorithm

Process finished with exit code 1

这是我的客户端.py

import ns_config
from netsuite.service import (client,
                          RecordRef,
                          ApplicationInfo,
                          Passport)


def make_passport():
role = RecordRef(internalId=ns_config.NS_ROLE)
return Passport(email=ns_config.NS_EMAIL,
                password=ns_config.NS_PASSWORD,
                account=ns_config.NS_ACCOUNT,
                role=role)


def login():
app_info = ApplicationInfo(applicationId=ns_config.NS_APPID)
passport = make_passport()
login = client.service.login(passport=passport, _soapheaders={'applicationInfo': app_info})

print('Login Response: ', login.status)
return client, app_info


passport = make_passport()
client, app_info = login()

WSDL_URL 是这样的:https ://webservices.sandbox.netsuite.com/wsdl/v2017_1_0/netsuite.wsdl 。这是我们拥有的 Netsuite 版本。

谁能告诉我我做错了什么?

4

1 回答 1

1

我相信 Passport 的正确命名空间是:

urn:core_2017_1.platform.webservices.netsuite.com

不是您的错误消息中的那个:

urn:types.core_2017_1.platform.webservices.netsuite.com

我是 zeep 和 netsuite 的新手,但我注意到到目前为止,无论参数或标头的类型是已知的,我都可以通过字符串键和字符串或嵌套的 dict 值传递一个普通的 dict,然后 zeep 会转动它进入正确的类型化 xml,而无需我提供命名空间或实例化和链接 xsd 对象。可能有助于简化您的代码。

于 2018-04-25T21:30:01.820 回答