Call to Live Market Data API giving error as below


  • @Moderator_2 @admin
    Hello Team ,
    I am trying to call Live Market data with the below payload , however it is giving me error as highlighted .
    Payload :
    payload = {
    "mode": "LTP",
    "exchangeTokens": {
    "NSE": [
    "3045", "881"
    ],
    "NFO": [
    "35078"
    ]
    }
    }
    headers = {
    'X-PrivateKey': '*******',
    'Accept': 'application/json',
    'X-SourceID': 'WEB',
    'X-ClientLocalIP': 'CLIENT_LOCAL_IP',
    'X-ClientPublicIP': 'CLIENT_PUBLIC_IP',
    'X-MACAddress': 'MAC_ADDRESS',
    'X-UserType': 'USER',
    'Authorization': 'twttoken is placed here ',
    'Accept': 'application/json',
    'X-SourceID': 'WEB',
    'Content-Type': 'application/json'
    }

    The Error ::
    **chunk = f'{len(chunk):X}\r\n'.encode('ascii') + chunk
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
    TypeError: can't concat str to bytes**


  • Hi @Sanky

    Apologies for delayed response.
    We have verified the payload and header from our end. Live Market Data API is working fine for the same.
    Kindly verify on the code for "TypeError: can't concat str to bytes" with the below reference.
    https://www.askpython.com/python/type-error-cant-concat-bytes-to-str#:~:text=To fix the “can't,without raising a type error.
    If the issue has not resolved. Please share the code snippet consumed for us to analyze further.

    Thanks & Regards,
    SmartAPI team