Is there a bug in this python module or am I using it the wrong way?

133 views Asked by At

lambda from getattr getting called with "connection" as a keyword argument? Am I misusing the code or is there a bug?

Code and traceback: 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')

Gives this traceback:

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 in api.py that the traceback refers to: https://github.com/bigcommerce/bigcommerce-api-python/blob/master/bigcommerce/api.py#L57

1

There are 1 answers

0
folkol On

According to the examples, create should be used like this:

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

Note: You should generate a new API KEY, since you published the current one in this question.