Python Forum
Getting a certain value from inside brackets.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a certain value from inside brackets.
#3
Hi there,
I'm a beginner so this problem might be very ease to solve. Nevertheless I posted this question a few days ago and got no helping answer. I hope that someone of you has an idea.

I'm doing a GET request:
requests.get('https://api.xyz.cloud/api/sites/%s?detailed=true' % xyz_site_id, timeout=None, headers=self.headers).json()
to a device that responds with the following raw data:
[{u'address': {u'altitude': None,
               u'area': u'',
               u'buildingNumber': None,
               u'country': None,
               u'latitude': None,
               u'longitude': None,
               u'street': u'',
               u'zip': u''},
  u'id': 63XXXX,
  u'levelOfAccess': None,
  u'name': u'Schuppen',
  u'siteKey': u'YBCL-HXXX'}]
I basically want to save the value of 'siteKey', meaning YBCL-HXXX into a variable to use this variable for further actions...

I had this problem before and could solve it using this method:
variableX = exampledata['siteKey']
Nevertheless, when using this method now I get the following error:
TypeError: list indices must be integers, not str

Btw. I have to use Python 2.7 due to various reasons...

I think it has to do with a different format of the raw data (a 'list').
I'm searching for a solution for hours now and hope that some of you can help me...
Best,
Leo
Reply


Messages In This Thread
Putting a specific value of a 'list' into a variable?! - by LeoT - Mar-01-2021, 02:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] [BeautifulSoup] Why does it turn inserted string's brackets into </>? Winfried 0 1,542 Sep-03-2022, 11:21 PM
Last Post: Winfried
  Reading list items without brackets and quotes jesse68 6 4,681 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Data pulled from SQL comes in brackets nickzsche 3 2,703 Jan-04-2022, 03:39 PM
Last Post: ibreeden
  For Loop and Use of Brackets to Modify Dictionary in Tic-Tac-Toe Game new_coder_231013 7 2,312 Dec-28-2021, 11:32 AM
Last Post: new_coder_231013
  Removing internal brackets from a string Astrikor 4 2,701 Jun-04-2020, 07:54 PM
Last Post: Astrikor
  Taking brackets out of list in print statement pythonprogrammer 3 2,428 Apr-13-2020, 12:25 PM
Last Post: perfringo
  printing a list contents without brackets in a print statement paracelx 1 2,153 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  Dictionnary brackets issue Reldaing 1 1,849 Nov-10-2019, 11:54 PM
Last Post: ichabod801
  how to remove brackets within a list A3G 17 18,347 Oct-16-2016, 02:34 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020