question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: 'dict_keys' object does not support indexing

See original GitHub issue

Hi

I’m trying to do a query on documentdb like this (tested with python 3.4 and 3.6):

query = { 'query': 'SELECT VALUE MAX(c.counter) FROM c' }    
#        
options = {} 
options['enableCrossPartitionQuery'] = True
#options['maxItemCount'] = 2
#
result_iterable = client.QueryDocuments(myCollection, query, options)
  
results = list(result_iterable);
print(results)

And get:

Traceback (most recent call last):
  File "documentdb.py", line 98, in <module>
    for i in result_iterable:
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/query_iterable.py", line 107, in __next__
    return next(self._ex_context)
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/execution_context/base_execution_context.py", line 103, in __next__
    return self.next()
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/execution_context/execution_dispatcher.py", line 70, in next
    return next(self._execution_context)
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/execution_context/base_execution_context.py", line 103, in __next__
    return self.next()
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/execution_context/execution_dispatcher.py", line 146, in next
    return next(self._endpoint)
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/execution_context/endpoint_component.py", line 42, in __next__
    return self.next()
  File "/usr/local/lib/python3.4/dist-packages/pydocumentdb/execution_context/endpoint_component.py", line 98, in next
    operator.aggregate(item[item.keys()[0]])
TypeError: 'dict_keys' object does not support indexing

See this link: https://stackoverflow.com/questions/18552001/accessing-dict-keys-element-by-index-in-python3

Could it be that line 98 in endpoint_component.py should have used next(iter(item)) instead of item.keys()[0] ?

Br. Rune

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
runemycommented, Jun 14, 2017

Minimal test case:

a = dict()
a.keys()[0]

Replace with:

a = dict()
next(iter(a))
0reactions
runemycommented, Jul 21, 2017

Any progress on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: 'dict_keys' object does not support indexing
keys() returns a dict_keys object which behaves a lot more like a set than a list . As such, it can't be indexed....
Read more >
Solved- TypeError: dict_keys object does not support indexing
In this article we learned that view object (dict_keys) returned by dict.keys() doesn't supports the indexing. If someone tries to select element from...
Read more >
T101801 "TypeError: 'dict_keys' object does not support ...
In Python 3 the dict.keys() method returns a dictionary view object, which does not support indexing. Details ...
Read more >
TypeError: 'dict_keys' object does not support indexing #217
I tired demo.ipynb at google colab. After installing the requirements I started to run the code. There arise an issue in the follwing...
Read more >
TypeError: 'dict_keys' object does not support ... - Google Groups
It looks like the issue is that `dict.keys()` returns different types of objects in Python 2 and 3. It returns plain list in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found