import pandas as pd
from smartapi import SmartConnect
from smartapi import SmartWebSocket
import json
obj = SmartConnect(api_key="vhidyTNq")
refreshToken = data['data']['refreshToken']
feedToken = obj.getfeedToken()
ss = SmartWebSocket(feedToken,"P78013")
obj=SmartConnect(api_key="vhidyTNq")
data = obj.generateSession("P78013","Ujhdy@2")
print(data)
parsed = json.loads(data)
print(parsed.jwtToken)
The result printed in the following format
{'status': True, 'message': 'SUCCESS', 'errorcode': '', 'data': {'clientcode': 'K98913', 'name': 'HPP', 'email': '', 'mobileno': '', 'exchanges': ['bse_cm', 'cde_fo', 'mcx_fo', 'ncx_fo', 'nse_cm', 'nse_fo'], 'products': ['CNC', 'NRML', 'MARGIN', 'MIS', 'BO', 'CO'], 'lastlogintime': '', 'broker': '', 'jwtToken': 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI6Iko4ODkxMyIsInJvbGVzIjowLCJ1c2VydHlwZSI6IlVTRVIiLCJpYXQiOjE2NTU3NTAxNDksImV4cCI6MTc0MjE1MDE0OX0.P1Ne0T0lTgScZJ1udMYRaJ32WeNDB-bZIwMg4uSAGC4RDFnYRsdvXGRyIEx7KS1LpQ6ndRIt7UjoyIewCs7HLA', 'refreshToken': 'eyJhbGciOiJIUzUxMiJ9.eyJ0b2tlbiI6IlJFRlJFU0gtVE9LRU4iLCJpYXQiOjE2NTU3NTAxNDl9.9DM1ggWfaervPe3qCpoDywfdb8kJ6okQrqZeR_mjsbGliqM7w0DdRyxTHyB7m-742Sfj9tVsZ4qQrOK0RQ9TmQ'}}
i am trying to filter out the 'jwtToken' value in the string format like below
jwtToken='Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VybmFtZSI.....'
CodePudding user response:
Update:
It seems that data
is a dict, then you can directly use data['data']['jwtToken']
to get the result.
If data
is a string, you can try using regular expression:
import re
re.search(r"'jwtToken': '(.*?)'", data).group(1)
CodePudding user response:
Try this:
print(parsed["data"]["jwtToken"])
Also, give the full code of your project will be appreciated.