generateSession issue with new TOPO API : Couldn't parse the JSON response received from the server: b


  • after upgraded the smartapi and providing the TOPO details, getting below error while generating the session.

    data = obj.generateSession(username,pwd,topo)
    Please provide the solution

    JSONDecodeError Traceback (most recent call last)
    C:\ProgramData\Anaconda3\lib\site-packages\smartapi\smartConnect.py in _request(self, route, method, parameters)
    187 try:
    --> 188 data = json.loads(r.content.decode("utf8"))
    189

    C:\ProgramData\Anaconda3\lib\json_init_.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    345 parse_constant is None and object_pairs_hook is None and not kw):
    --> 346 return _default_decoder.decode(s)
    347 if cls is None:

    C:\ProgramData\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
    336 """
    --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    338 end = _w(s, end).end()

    C:\ProgramData\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
    354 except StopIteration as err:
    --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
    356 return obj, end

    JSONDecodeError: Expecting value: line 1 column 1 (char 0)

    During handling of the above exception, another exception occurred:

    DataException Traceback (most recent call last)
    ~\AppData\Local\Temp/ipykernel_4956/2840288024.py in <module>
    ----> 1 data = obj.generateSession(username,pwd,topo)

    C:\ProgramData\Anaconda3\lib\site-packages\smartapi\smartConnect.py in generateSession(self, clientCode, password, totp)
    226
    227 params={"clientcode":clientCode,"password":password,"totp":totp}
    --> 228 loginResultObject=self._postRequest("api.login",params)
    229
    230 if loginResultObject['status']==True:

    C:\ProgramData\Anaconda3\lib\site-packages\smartapi\smartConnect.py in _postRequest(self, route, params)
    218 def _postRequest(self, route, params=None):
    219 """Alias for sending a POST request."""
    --> 220 return self._request(route, "POST", params)
    221 def _getRequest(self, route, params=None):
    222 """Alias for sending a GET request."""

    C:\ProgramData\Anaconda3\lib\site-packages\smartapi\smartConnect.py in _request(self, route, method, parameters)
    189
    190 except ValueError:
    --> 191 raise ex.DataException("Couldn't parse the JSON response received from the server: {content}".format(
    192 content=r.content))
    193

    DataException: Couldn't parse the JSON response received from the server: b''


  • @daleep_angel said in generateSession issue with new TOPO API : Couldn't parse the JSON response received from the server: b:

    Got solution as below.

    Install pyopt library : pip install pyotp

    import pyotp

    use the topo detail with pyotp as below:

    topo = Trading_api_key_details.topo
    topt = pyotp.TOTP(topo)
    topt = topt.now()
    data = obj.generateSession(username,pwd,topt)
    refreshToken= data['data']['refreshToken']
    print(data)


  • Got solution as below.

    Install pyopt library : pip install pyotp

    import pyotp

    use the topo detail with pyotp as below:

    topo = Trading_api_key_details.topo
    topt = pyotp.TOTP(topo)
    topt = topt.now()
    data = obj.generateSession(username,pwd,topt)
    refreshToken= data['data']['refreshToken']
    print(data)