Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python进行JSON调用_Python_Json - Fatal编程技术网

使用Python进行JSON调用

使用Python进行JSON调用,python,json,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_b

这是我尝试使用的类

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]
这是我的剧本:

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
我在产品中遗漏了一些东西。get()…但是什么

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) 
回溯(最近一次呼叫最后一次):
文件“C:\wget\bin\test\u bigcommerce.py”,第8行,在
products\u list=bigcommerce.api.products.get()
TypeError:必须使用Products实例作为第一个参数调用未绑定的方法get()(改为不获取任何内容)

另外,由于我更改了主机和api密钥以将其发布到公共站点,因此代码将无法工作

您有一个类
产品
,但从不创建该类的实例

改为创建一个实例:

bigcommerce.api.Products().get()

实际问题是什么?预期结果和实际结果是什么?我正在尝试使用Python获取我的产品列表…当我运行代码时,我得到以下错误…回溯(最近一次调用):文件“C:\wget\bin\test\u bigcommerce.py”,第8行,在products\u list=bigcommerce.api.products.get()类型错误:unbound method get()必须以Products实例作为第一个参数调用(没有得到任何结果)。问题显然出在
bigcommerce
模块中,或者您如何使用它。您应该查看文档和/或在更具体的论坛上提问。如果没有更多信息,您就不可能得到答案。不幸的是,bigcommerce python api的文档很少……我对python还是相当陌生,而且对使用JSON调用网站也非常陌生……这“('get','/products?limit=%s&page=%s”“(self.paginate_by,self.current_page))”如何翻译成.get()call?@user2152584:
字符串%tuple
是Python格式的运算符。结果是另一个字符串,其中“%s”替换为元组的值。该字符串可能直接用作要获取的url。