我有一个包含多个字符串的字符串对象..我想提取 "_json": 之后的部分,直到它到达 } 但是当我在我的代码中给出这个时,它告诉索引越界异常。 任何人都可以帮助提取那部分 我得到的字符串是
---------------------------------------------------------------------------
ClientError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/s3fs/core.py in _lsdir(self,path,refresh,max_items,delimiter,prefix)
573 dircache = []
--> 574 async for i in it:
575 dircache.extend(i.get("CommonPrefixes",[]))
/opt/conda/lib/python3.7/site-packages/aiobotocore/paginate.py in __anext__(self)
31 while True:
---> 32 response = await self._make_request(current_kwargs)
33 parsed = self._extract_parsed_response(response)
/opt/conda/lib/python3.7/site-packages/aiobotocore/client.py in _make_api_call(self,operation_name,api_params)
154 error_class = self.exceptions.from_code(error_code)
--> 155 raise error_class(parsed_response,operation_name)
156 else:
ClientError: An error occurred (accessDenied) when calling the ListObjectsV2 operation: access Denied
The above exception was the direct cause of the following exception:
PermissionError Traceback (most recent call last)
<ipython-input-162-af0f8b8e4877> in <module>
9 fs = s3fs.S3FileSystem(session=fs_session)
10 bucket_name = "my_data_bucket"
---> 11 print(fs.ls(bucket_name))
/opt/conda/lib/python3.7/site-packages/fsspec/asyn.py in wrapper(*args,**kwargs)
86 def wrapper(*args,**kwargs):
87 self = obj or args[0]
---> 88 return sync(self.loop,func,*args,**kwargs)
89
90 return wrapper
/opt/conda/lib/python3.7/site-packages/fsspec/asyn.py in sync(loop,timeout,**kwargs)
67 raise FSTimeoutError
68 if isinstance(result[0],BaseException):
---> 69 raise result[0]
70 return result[0]
71
/opt/conda/lib/python3.7/site-packages/fsspec/asyn.py in _runner(event,coro,result,timeout)
23 coro = asyncio.wait_for(coro,timeout=timeout)
24 try:
---> 25 result[0] = await coro
26 except Exception as ex:
27 result[0] = ex
/opt/conda/lib/python3.7/site-packages/s3fs/core.py in _ls(self,detail,refresh)
777 files = await self._lsbuckets(refresh)
778 else:
--> 779 files = await self._lsdir(path,refresh)
780 if not files and "/" in path:
781 files = await self._lsdir(self._parent(path),refresh=refresh)
/opt/conda/lib/python3.7/site-packages/s3fs/core.py in _lsdir(self,prefix)
595 f["name"] = f["Key"]
596 except ClientError as e:
--> 597 raise translate_boto_error(e)
598
599 if delimiter and files:
PermissionError: access Denied
但是当我在代码中给出这个时,它给出了例外
===username===>>{"profile":{"id":"xxxxxx","name":{},"_raw":"{\"sub\":\"xxxxx\",\"country\":\"US\",\"firstname\":\"xxxx\",\"employeetype\":\"XXXX\",\"mail\":\"abc@yz.com\",\"gehrbusinesssegment\":\"avav\",\"gessobusinessunit\":\"AVI DT-xxxxx Engineering\",\"gessouid\":\"C2B0A5EB-8A20-170F-BF3E-002128B20D70\",\"cn\":\"Saha,Romit\",\"title\":\"Project Manager (Backend)\",\"georaclehrid\":\"xxxxx\",\"lastname\":\"Saha\",\"uid\":\"xxxxx\",\"groupNAME\":[\"@GE AWS_bu-readonly_175070699551\",\"@GE AWS_bu-readonly_639624358806\",\"@AVIATION MRO Fulfillment Operations Advisor\",\"@POWER pge_role_super_user_dev\",\"@AVIATION DISE Friends of the Family\",\"@AVIATION MOA Users - Editor access\",\"@AVIATION MOA-Viewer-Users\",\"@Gas Power Smartshop Users\",\"@AVIATION US VPN GROUP\",\"@Digital Emergency Change Notification 23\"],\"gessocompanyname\":\"XXXXXX\",\"gehrindustrygroup\":\"XXXXXX\",\"gessojobfunction\":\"Information Technology\",\"street\":\"XXXXXPlaza\",\"location\":\"XXXX\",\"state\":\"XXX\",\"geECIndicator\":\"N\"}\r\n","_json":{"sub":"XXXX","country":"US","firstname":"Romit","employeetype":"XXX","mail":"XXX@ge.com","gehrbusinesssegment":"XXX","gessobusinessunit":"AVI DT-Data Infrastructure & Software Engineering","gessouid":"C2B0A5EB-8A20-170F-BF3E-002128B20D70","cn":"Saha,Romit","title":"XXXXXX(Backend)","georaclehrid":"XXXX","lastname":"Saha","uid":"502622018","groupNAME":["@GE AWS_bu-readonly_175070699551","@GE AWS_bu-readonly_639624358806","@AVIATION MRO Fulfillment Operations Advisor","@POWER pge_role_super_user_dev","@AVIATION DISE Friends of the Family","@AVIATION MOA Users - Editor access","@AVIATION MOA-Viewer-Users","@Gas Power Smartshop Users","@AVIATION US VPN GROUP","@Digital Emergency Change Notification 23"],"gessocompanyname":"XXXXX","gehrindustrygroup":"GE Aviation","gessojobfunction":"Information Technology","street":"XXXXX Plaza","location":"XXXX","state":"XXX","geECIndicator":"N"}},"accessTokenExp":1627090679000,"accessToken":"XXXXX","refreshTokenExp":1627105079000,"refreshToken":"XXXXX","user_info":{"family_name":"Saha","given_name":"Romit","user_name":"XXXXX"}}
错误:
String json = username.substring(username.indexOf("_json") + 1,username.indexOf('}'));