使用Python在下一页url请求中出现错误404

时间:2015-12-29 07:35:19

标签: python python-requests

我正在尝试通过python API从Flipkart.com获取数据。响应有一个'nextUrl'标记,我试图获取以获取其他数据。但它一直给我一个错误404.

我的代码:

    url = "https://api.flipkart.net/sellers/v2/returns"
    next_url = "https://api.flipkart.net/sellers/v2{0}"

    payload = {'source':return_source,
                'createdAfter':createdAfter}

    response = self.session.get(url, params=payload)
    orders = []
    resp_json = response.json()
    print resp_json

    for each in resp_json['returnItems']:
        orders.append(each)

    try:
        while resp_json['hasMore'] == True:
            new_url = ''
            new_url = next_url.format(resp_json['nextUrl'])
            response = self.session.get(new_url)
            resp_json = response.json()
            for each in resp_json['returnItems']:
                orders.append(each)
    except:
        print "Next page return url not working"

我得到的第一个回应:

{u'nextUrl': u'/returns/search/ewogICJmaWx0ZXIiIDogewogICAgInNlcnZpY2VfcHJvZmlsZSIgOiBudWxsLAogICAgInR5cGUiIDogWyAiY291cmllcl9yZXR1cm4iIF0sCiAgICAic2hpcG1lbnRfdHlwZXMiIDogbnVsbCwKICAgICJzaGlwbWVudF9zdGF0dXMiIDogbnVsbCwKICAgICJyZXR1cm5fc3RhdHVzIiA6IG51bGwsCiAgICAic2hpcG1lbnRfZXhwZWN0YXRpb25zIiA6IG51bGwsCiAgICAic2t1IiA6IG51bGwsCiAgICAicHJvbWlzZV9icmVhY2giIDogbnVsbCwKICAgICJhcHByb3ZlZCIgOiBudWxsLAogICAgInByb21pc2UiIDogbnVsbCwKICAgICJvdXRfZm9yX2RlbGl2ZXJ5IiA6IG51bGwsCiAgICAicmV0dXJuX2NvbXBsZXRlZCIgOiBudWxsLAogICAgImNyZWF0ZWRfYWZ0ZXIiIDogMTQ0NzQzOTQwMCwKICAgICJtb2RpZmllZF9hZnRlciIgOiAwCiAgfSwKICAicGFnaW5hdGlvbiIgOiB7CiAgICAic3RhcnRpbmdfcGFnZSIgOiAyLAogICAgInBhZ2Vfc2l6ZSIgOiAyNQogIH0sCiAgInNvcnQiIDogbnVsbAp9', u'hasMore': True, u'returnItems': [{u'orderId': u'OD40476241666874334000', u'returnId': 4058426316, u'orderItemId': u'4476166687432143400', u'expectedDate': None, u'updatedDate': None, u'subReason': None, u'shipmentStatus': u'in_transit', u'comments': u'Customer requested to cancel the order', u'shipmentId': None, u'reason': u'order_cancelled', u'courierName': None, u'status': u'cancelled', u'trackingId': u'5962062676508084', u'createdDate': u'2015-12-28T23:10:23+05:30', u'approvedOn': None, u'sellerId': u'test_seller_1', u'type': u'courier_return', u'orderDate': u'2015-12-22T05:15:53.000Z', u'quantity': 1}]}

我在尝试获取其他页面时遇到了什么问题?

它一直只为'nextUrl'提供状态代码404。

0 个答案:

没有答案