I'm getting a memory address with each request I send.
Closed this issue · 5 comments
Every time I send a GET request to pull data from Big Commerce, I get a Memory Address with a python dictionary inside it.
How can I get just the python dictionary inside it instead?
Can you give us a code sample along with the output? Thanks!
Code:
import bigcommerce
api = bigcommerce.api.BigcommerceApi(host='*************.mybigcommerce.com', basic_auth=('************', '************************************************'))
productOrdersList = []
def pullOrdersProductsData():
for x in range(614530, 614539):
try:
productOrdersList.append(api.Orders.get(id="{}".format(x)).products())
except:
pass
return None
def saveToFile():
f = open("allOrderProductsData", "w", encoding='utf-8')
f.write("\n".join(map(lambda x: str(x), productOrdersList)))
f.close()
return None
pullOrdersProductsData()
saveToFile()
Output:
[<OrderProducts at 0x3e92728, {'quantity_shipped': 0, 'total_tax': '0.0000', 'wrapping_cost_tax': '0.0000', 'quantity': 1, 'parent_order_product_id': None, 'configurable_fields': [], 'cost_price_tax': '0.0000', 'fixed_shipping_cost': '0.0000', 'base_wrapping_cost': '0.0000', 'cost_price_inc_tax': '0.0000', 'base_price': '99.0000', 'wrapping_cost_inc_tax': '0.0000', 'ebay_item_id': '', 'return_id': 0, 'base_cost_price': '0.0000', 'option_set_id': 15, 'cost_price_ex_tax': '0.0000', 'event_date': '', 'price_ex_tax': '99.0000', 'name': 'University of Timbuktu Bachelor Set', 'wrapping_cost_ex_tax': '0.0000', 'order_id': 614534, 'refund_amount': '0.0000', 'total_inc_tax': '99.0000', 'id': 3, 'price_inc_tax': '99.0000', 'wrapping_name': '', 'bin_picking_number': '', 'base_total': '99.0000', 'product_id': 83, 'is_bundled_product ': False, 'sku': 'S-TIM-BAC-STD', 'total_ex_tax': '99.0000', 'is_refunded': False, 'event_name': None, 'applied_discounts': [{'amount': 99, 'id': 'total-coupon'}], 'price_tax': '0.0000', 'product_options': [{'display_style': 'Pick list', 'name': 'Bachelor gown size', 'id': 2, 'type': 'Product list', 'value': '77', 'option_id': 19, 'order_product_id': 3, 'display_name': 'Gown size', 'product_option_id': 95, 'display_value': 'Cambridge-Style Bachelor Gown, Size L'}, {'display_style': 'Pick list', 'name': 'Trencher size', 'id': 3, 'type': 'Product list', 'value': '80', 'option_id': 20, 'order_product_id': 3, 'display_name': 'Trencher size', 'product_option_id': 97, 'display_value': 'Bachelor and Masters Trencher, Size L'}], 'type': 'physical', 'order_address_id': 2, 'weight': '3.0000', 'ebay_transaction_id': '', 'wrapping_message': ''}>, <OrderProducts at 0x3e92138, {'quantity_shipped': 0, 'total_tax': '0.0000', 'wrapping_cost_tax': '0.0000', 'quantity': 1, 'parent_order_product_id': 3, 'configurable_fields': [], 'cost_price_tax': '0.0000', 'fixed_shipping_cost': '0.0000', 'base_wrapping_cost': '0.0000', 'cost_price_inc_tax': '0.0000', 'base_price': '0.0000', 'wrapping_cost_inc_tax': '0.0000', 'ebay_item_id': '', 'return_id': 0, 'base_cost_price': '0.0000', 'option_set_id': None, 'cost_price_ex_tax': '0.0000', 'event_date': '', 'price_ex_tax': '0.0000', 'name': 'Cambridge-Style Bachelor Gown, Size L', 'wrapping_cost_ex_tax': '0.0000', 'order_id': 614534, 'refund_amount': '0.0000', 'total_inc_tax': '0.0000', 'id': 4, 'price_inc_tax': '0.0000', 'wrapping_name': '', 'bin_picking_number': '', 'base_total': '0.0000', 'product_id': 80, 'is_bundled_product ': True, 'sku': 'G-CAM-BAC-L', 'total_ex_tax': '0.0000', 'is_refunded': False, 'event_name': None, 'applied_discounts': [], 'price_tax': '0.0000', 'product_options': [], 'type': 'physical', 'order_address_id': 2, 'weight': '0.0000', 'ebay_transaction_id': '', 'wrapping_message': ''}>, <OrderProducts at 0x3e92778, {'quantity_shipped': 0, 'total_tax': '0.0000', 'wrapping_cost_tax': '0.0000', 'quantity': 1, 'parent_order_product_id': 3, 'configurable_fields': [], 'cost_price_tax': '0.0000', 'fixed_shipping_cost': '0.0000', 'base_wrapping_cost': '0.0000', 'cost_price_inc_tax': '0.0000', 'base_price': '0.0000', 'wrapping_cost_inc_tax': '0.0000', 'ebay_item_id': '', 'return_id': 0, 'base_cost_price': '0.0000', 'option_set_id': None, 'cost_price_ex_tax': '0.0000', 'event_date': '', 'price_ex_tax': '0.0000', 'name': 'Bachelor and Masters Trencher, Size L', 'wrapping_cost_ex_tax': '0.0000', 'order_id': 614534, 'refund_amount': '0.0000', 'total_inc_tax': '0.0000', 'id': 5, 'price_inc_tax': '0.0000', 'wrapping_name': '', 'bin_picking_number': '', 'base_total': '0.0000', 'product_id': 87, 'is_bundled_product ': True, 'sku': 'C-STD-B&M-L', 'total_ex_tax': '0.0000', 'is_refunded': False, 'event_name': None, 'applied_discounts': [], 'price_tax': '0.0000', 'product_options': [], 'type': 'physical', 'order_address_id': 2, 'weight': '0.0000', 'ebay_transaction_id': '', 'wrapping_message': ''}>]
This is because you are casting your OrderProducts
object to a string when writing to the file. Because we don't define __str__
See discussion here, the default implementation of casting an object to a string is used, which is what you are seeing here. You'll need to do something a little more customized to print values to a file.
I still get the memory address, even without trying to save to a file.
Here is the code:
import bigcommerce
api = bigcommerce.api.BigcommerceApi(host='store-flx4x.mybigcommerce.com', basic_auth=('Filipe', '************************'))
productOrdersList = []
for x in range(614530, 614539):
try:
productOrdersList.append(api.Orders.get(id="{}".format(x)).products())
except:
pass
print(productOrdersList)
Or simply if I type in the console:
a = api.Orders.get(id="614535").products()
print(a)
I will still get the memory address. Am I missing something?