2015-06-21 130 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,因爲您已在此問題中發佈了當前的一個。

相關問題