2015-06-21 131 views
0

来自getattr的lambda以“连接”作为关键字参数被调用?我滥用了代码还是有错误?在这个python模块中有错误还是我用错了?

代码和追踪:https://github.com/bigcommerce/bigcommerce-api-python/issues/32

#!/usr/bin/env python2 
import bigcommerce 
import bigcommerce.api 

BIG_URL = 'store-45eg5.mybigcommerce.com' 
BIG_USER = 'henry' 
BIG_KEY = '10f0f4f371f7953c4d7d7809b62463281f15c829' 

api = bigcommerce.api.BigcommerceApi(host=BIG_URL, basic_auth=(BIG_USER, BIG_KEY)) 
def get_category_id(name): 
    get_request = api.Categories.get(name) 
    try: 
     cat_list = api.Categories.all(name=name) 
      if cat_list: 
       return cat_list[0]['id'] 
      else: 
       return None 
      except: 
       return None 
def create_category(name): 
    rp = api.Categories.create(name) 
    if rp.status == 201: 
     return rp.json()['id'] 
    else: 
     return get_category_id(name) 
create_category('anothertestingcat') 

给出了这样的回溯:

Traceback (most recent call last): 
File "./bigcommerceimporter.py", line 50, in 
create_category('anothertestingcat') 
File "./bigcommerceimporter.py", line 44, in create_category 
rp = api.Categories.create(name) 
File "/home/henry/big_test_zone/local/lib/python2.7/site-packages/bigcommerce/api.py", line 57, in 
return lambda args, *kwargs: (getattr(self.resource_class, item))(args, connection=self.connection, *kwargs) 
TypeError: create() got multiple values for keyword argument 'connection' 

Line在api.py的追溯是指:https://github.com/bigcommerce/bigcommerce-api-python/blob/master/bigcommerce/api.py#L57

+4

请不要链接到外部代码段,而应包含一个自包含的示例,在您的帖子正文中展示问题。 – BrenBarn

+0

您使用它的方式可能不正确 – rlms

+0

https://bpaste.net/show/ebe9be3ea7ce代码 – user2970983

回答

1

按照examples,创建宜像这样使用:

api.Categories.create(name = 'anothertestingcat') 

注意:您应该生成一个新的API KEY,因为您已在此问题中发布了当前的一个。

相关问题