2013-03-09 47 views
-2

這裏是我試圖使用使用Python的JSON調用

class Products(Resource): 
    """The collection of products in a store""" 

    def get(self): 
     """Returns list of products""" 
     products_list = self.client.request_json('GET', '/products?limit=%s&page=%s' % (self.paginate_by, self.current_page)) 
     return [Product(product) for product in products_list] 

這裏是我的腳本類:在Products.get

import bigcommerce.api 

bigcommerce.api.Connection.host = 'https://store-qvek.mybigcommerce.com' 
bigcommerce.api.Connection.user = 'admin' 
bigcommerce.api.Connection.api_key = '272956b18e3a7c269b413385908cc7371f5c41' 


products_list = bigcommerce.api.Products.get() 
for product in products_list: 
    print product.name 

我失去了一些東西()。 ...但是什麼?

Traceback (most recent call last): 
    File "C:\wget\bin\test_bigcommerce.py", line 8, in <module> 
    products_list = bigcommerce.api.Products.get() 
TypeError: unbound method get() must be called with Products instance as first argument (got nothing instead) 

P.S,因爲我已經改變了主機和API密鑰才能將它張貼公開的代碼將無法正常工作。

+1

什麼實際問題?預期的和實際的結果是什麼? – 2013-03-09 22:34:15

+0

我試圖讓我的產品使用Python列表....當我運行我的代碼,我得到以下錯誤....回溯(最近調用最後): 文件「C:\ wget \ bin \ test_bigcommerce.py「,第8行,在 products_list = bigcommerce.api.Products.get() TypeError:unbound方法get()必須用Products實例作爲第一個參數調用(沒有任何代替) – user2152584 2013-03-09 22:36:23

+0

問題顯然在'bigcommerce'模塊或你如何使用它。您應該查看文檔和/或在更具體的論壇中詢問。沒有更多的信息,你不可能得到答案。 – rodrigo 2013-03-09 22:36:52

回答

0

你有一個類Products但從來沒有創建一個實例。

,而不是創建一個實例:

bigcommerce.api.Products().get() 
+0

:) :) :)謝謝! – user2152584 2013-03-09 23:19:50