'TypeError: 'NoneType' object is not subscriptable? python3

I need your help line 8 gives an error below:

Price Array:  [40097.5, 40097.501, 40097.502, 40097.503, 40097.504, 40097.505, 40097.506, 40097.507, 40097.508]
Allocated Quantities:  [2, 4, 8, 16, 32, 64, 128, 256, 512]
Take Profits [0, 40097.491, 40097.492, 40097.493, 40097.494, 40097.495, 40097.496, 40097.497, 40097.498]
({'ret_code': 130021, 'ret_msg': 'oc_diff[814580712500], new_oc[814580712500] with ob[0]+AB[96730135992]', 'ext_code': '', 'ext_info': '', 'result': None, 'time_now': '1645296976.020171', 'rate_limit_status': 99, 'rate_limit_reset_ms': 1645296976015, 'rate_limit': 100}, <bravado.requests_client.RequestsResponseAdapter object at 0x000001E55B603FA0>)
({'ret_code': 130021, 'ret_msg': 'oc_diff[1629161425000], new_oc[1629161425000] with ob[0]+AB[96730135992]', 'ext_code': '', 'ext_info': '', 'result': None, 'time_now': '1645296976.390693', 'rate_limit_status': 98, 'rate_limit_reset_ms': 1645296976387, 'rate_limit': 100}, <bravado.requests_client.RequestsResponseAdapter object at 0x000001E55B603E50>)
Traceback (most recent call last):
  File "C:\Users\Trad\trading-bot\trader.py", line 8, in <module>
    temp_order = order[0]['result']['order_id']
TypeError: 'NoneType' object is not subscriptable

This is the part of the python script.

if 0 < i < noSteps:
    order = (client.LinearOrder.LinearOrder_new(side=side, symbol="BTCUSDT", order_type="Limit",
                                                qty=allocatedQuantities[i], price=priceArray[i],
                                                time_in_force="GoodTillCancel",
                                                reduce_only=False, close_on_trigger=False,
                                                take_profit=takeProfits[i]).result())
    print(order)
    temp_order = order[0]['result']['order_id']
    ordersArray.append(temp_order)


Solution 1:[1]

The result key in your order[0] object points to None

You can't sub script a None

Instead of this:

temp_order = order[0]['result']['order_id']

You are effectively doing this:

temp_order = None['order_id']
{
    'ret_code': 130021, 
    'ret_msg': 'oc_diff[1629161425000], new_oc[1629161425000] with ob[0]+AB[96730135992]',
    'ext_code': '',
    'ext_info': '',
    'result': None,   # <---- This is causing your problem
    'time_now': '1645296976.390693',
    'rate_limit_status': 98,
    'rate_limit_reset_ms': 1645296976387,
    'rate_limit': 100
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JamesRoberts