首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >创建betfair.py API调用时类型错误

创建betfair.py API调用时类型错误
EN

Stack Overflow用户
提问于 2017-10-14 11:47:58
回答 1查看 183关注 0票数 0

我刚刚将一些代码移到了一个Ubuntu16.04.2 anaconda安装程序中,当调用代码时,我不理解它在许多其他机器上运行良好时的类型错误。

错误为我复制了下面回购中的所有网球市场示例代码,以及一个请求,如:

代码语言:javascript
复制
from betfair import Betfair
client = Betfair("app key needed here", "path to ssh key here")
client.login(username, password)
client.keep_alive()

client.list_market_book(market_ids=['1.135391020'], price_projection=dict(priceData=['EX_BEST_OFFERS']))

代码语言:javascript
复制
from betfair.models import MarketFilter
event_types = client.list_event_types(
    MarketFilter(text_query='tennis')
)
print(len(event_types))                 # 2
print(event_types[0].event_type.name)   # 'Tennis'
tennis_event_type = event_types[0]
markets = client.list_market_catalogue(
    MarketFilter(event_type_ids=[tennis_event_type.event_type.id])
)
markets[0].market_name 

尽管在windows安装上运行的代码相同,但两者都引发下列类型错误:

代码语言:javascript
复制
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-69b51cf78438> in <module>()
      1 event_types = client.list_event_types(
----> 2     MarketFilter(text_query='tennis')
      3 )
      4 print(len(event_types))                 # 2
      5 print(event_types[0].event_type.name)   # 'Tennis'

<decorator-gen-125> in list_event_types(self, filter, locale)

/home/user/anaconda2/lib/python2.7/site-packages/betfair/utils.pyc in requires_login(func, *args, **kwargs)
    121     self = args[0]
    122     if self.session_token:
--> 123         return func(*args, **kwargs)
    124     raise exceptions.NotLoggedIn()

/home/user/anaconda2/lib/python2.7/site-packages/betfair/betfair.pyc in list_event_types(self, filter, locale)
    148             'listEventTypes',
    149             utils.get_kwargs(locals()),
--> 150             model=models.EventTypeResult,
    151         )
    152 

/home/user/anaconda2/lib/python2.7/site-packages/betfair/betfair.pyc in make_api_request(self, base, method, params, codes, model)
     87         utils.check_status_code(response, codes=codes)
     88         result = utils.result_or_error(response)
---> 89         return utils.process_result(result, model)
     90 
     91     # Authentication methods

/home/user/anaconda2/lib/python2.7/site-packages/betfair/utils.pyc in process_result(result, model)
     81         return result
     82     if isinstance(result, collections.Sequence):
---> 83         return [model(**item) for item in result]
     84     return model(**result)
     85 

/home/user/anaconda2/lib/python2.7/site-packages/betfair/meta/models.pyc in __init__(self, **data)
     24     def __init__(self, **data):
     25         super(BetfairModel, self).__init__()
---> 26         self.import_data(data)
     27 
     28     def import_data(self, data, **kwargs):

/home/user/anaconda2/lib/python2.7/site-packages/betfair/meta/models.pyc in import_data(self, data, **kwargs)
     28     def import_data(self, data, **kwargs):
     29         kwargs['strict'] = False
---> 30         return super(BetfairModel, self).import_data(data, **kwargs)

/home/user/anaconda2/lib/python2.7/site-packages/schematics/models.pyc in import_data(self, raw_data, recursive, **kwargs)
    269             The data to be imported.
    270         """
--> 271         data = self._convert(raw_data, trusted_data=_dict(self), recursive=recursive, **kwargs)
    272         self._data.converted.update(data)
    273         if kwargs.get('validate'):

/home/user/anaconda2/lib/python2.7/site-packages/schematics/models.pyc in _convert(self, raw_data, context, **kwargs)
    293         should_validate = getattr(context, 'validate', kwargs.get('validate', False))
    294         func = validate if should_validate else convert
--> 295         return func(self._schema, self, raw_data=raw_data, oo=True, context=context, **kwargs)
    296 
    297     def export(self, field_converter=None, role=None, app_data=None, **kwargs):

/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in convert(cls, mutable, raw_data, **kwargs)
    427 
    428 def convert(cls, mutable, raw_data=None, **kwargs):
--> 429     return import_loop(cls, mutable, raw_data, import_converter, **kwargs)
    430 
    431 

/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in import_loop(schema, mutable, raw_data, field_converter, trusted_data, mapping, partial, strict, init_values, apply_defaults, convert, validate, new, oo, recursive, app_data, context)
    153                 field_context = context
    154             try:
--> 155                 value = _field_converter(field, value, field_context)
    156             except (FieldError, CompoundError) as exc:
    157                 errors[serialized_field_name] = exc

/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in __call__(self, *args)
    354 
    355     def __call__(self, *args):
--> 356         return self.func(*args)
    357 
    358 

/home/user/anaconda2/lib/python2.7/site-packages/schematics/transforms.pyc in import_converter(field, value, context)
    382     if value is None or value is Undefined:
    383         return value
--> 384     return field.convert(value, context)
    385 
    386 

/home/user/anaconda2/lib/python2.7/site-packages/schematics/types/compound.pyc in convert(self, value, context)
     34     def convert(self, value, context=None):
     35         context = context or get_import_context()
---> 36         return self._convert(value, context)
     37 
     38     def _convert(self, value, context):

/home/user/anaconda2/lib/python2.7/site-packages/schematics/types/compound.pyc in _convert(self, value, context)
    131                 "Input must be a mapping or '%s' instance" % self.model_class.__name__)
    132         if context.convert and context.oo:
--> 133             return model_class(value, context=context)
    134         else:
    135             return model_class.convert(value, context=context)

TypeError: __init__() takes exactly 1 argument (3 given)

更奇怪的是,这样的请求:

代码语言:javascript
复制
client.list_market_catalogue(MarketFilter(market_ids=['1.135391020']))

效果很好。

python 2.7.13,Anaconda 4.4.0,Ubuntu 16.04.2

知道是什么导致的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-17 06:35:39

从痕迹上看,我觉得原理图库是你的问题。在本文撰写之时,检查关于betfair的公开问题时,有一张关于破坏api的原理图的公开票证。看来,作者没有将示意图排除在需求之外,而是需要1.1.1版。我猜你已经在电脑上安装了示意图2.0,导致了这个问题。

在未来发现这种情况的一种方法是pip freeze工作环境并区分坏的环境。此外,在移动到新机器时,您可以使用pip freeze的输出复制环境,并避免出现像这样的混乱版本问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46744190

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档