【问题标题】:How to get all customers data from Shopify Python API?如何从 Shopify Python API 获取所有客户数据?
【发布时间】:2020-04-23 14:32:55
【问题描述】:

对于私有 Shopify 应用,我想检索所有客户数据并写入 csv 文件。我尝试了下面的选项来一次获取分页 250 条记录。但我收到一个错误: HTTPError: 错误请求

shopify.ShopifyResource.set_site(shop_url)  
import sys  
import pandas as pd  


% Get all customers  
def get_all_resources(resource, **kwargs):  
resource_count = resource.count(**kwargs)  
resources = []  
if resource_count > 0:  
    for page in range(1, ((resource_count-1) // 250) + 2):  
        kwargs.update({"limit" : 250, "page" : page})  
        resources.extend(resource.find(**kwargs))    
return resources  

all_customers = get_all_resources(shopify.Customer)  
data=[]  
for customer in all_customers:  
  tempdata=[]  
  tempdata.append(customer.id)  
  tempdata.append(customer.first_name)  
  tempdata.append(customer.last_name)  
  tempdata.append(customer.addresses)  
  tempdata.append(customer.phone)  
  tempdata.append(customer.email)  
  data.append(tempdata)  

df=pd.DataFrame(data,columns=['CustomerCode','FirstName','LastName','Address','MobileNo','Email'])  
df.to_csv('CustomerDataFromServer.csv',index=False)  

shopify.ShopifyResource.clear_session()

【问题讨论】:

  • 如果您更具体地了解哪一行引发了错误,这将有所帮助。我不熟悉shopify API,但想知道resource_count = resource.count(**kwargs) 在kwargs 为空时是否有效?无论如何,kwargs 在那个函数中有什么意义 - 它只被调用一次,带有一个 arg,所以kwargs 总是空的。使用函数本地的字典可能会更好。

标签: python pandas shopify


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-20
    • 1970-01-01
    • 1970-01-01
    • 2015-09-10
    相关资源
    最近更新 更多