I recieved a server response (r = request.get(url,auth) with data that I searched using 'api/2/search?jql=' with certain paramaters I need. However, how do I get or print the issueId number (only) of the tickets in the list of the search?
For example:
The data would look like:
{u'issues': [{u'key': u'x-123', u'fields': {u'customfield_123': None}......}
And, I would like to get the value/string 'x-123' (only) from 'key'.
I have done the following, but to no avail:
r.json()['issues'] #returns all values for issues
r.json()['issues':'key'] # returns TypeError: unhashable type.
Thanks in advance for those who help.
"r.json()['issues':'key'] # returns TypeError: unhashable type."
The problem is that you can't use a list as the key in a dict, since dict keys need to be immutable. This means that when you try to hash an unhashable object it will result an error. For ex. when you use a list as a key in the dictionary , this cannot be done because lists can't be hashed. The standard way to solve this issue is to cast a list to a tuple . TypeError: unhashable type: 'list' usually means that you are trying to use a list as an hash argument. The standard way to solve this issue is to cast a list to tuple.
Though tuples may seem similar to lists, they are often used in different situations and for different purposes. Tuples can be used as keys if they contain only strings, numbers, or tuples; if a tuple contains any mutable object either directly or indirectly, it cannot be used as a key. You can’t use lists as key.
Nevermind. I figured it out.
It is a dictionary nested in a list that is nested in a dictionary. Therefore, the correct call would look something like:
data[‘issues'][0][‘key']
Thanks anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.