wikitools icon indicating copy to clipboard operation
wikitools copied to clipboard

TypeError on certain queries

Open rblakemesser opened this issue 11 years ago • 1 comments

Greetings! I think I found a bug--

Try this:

import wikitools file_query = {'action': 'query', 'titles': u'Image:MLK and Malcolm X USNWR cropped.jpg', 'prop': 'imageinfo', 'iiprop': 'extmetadata'}

file_request = wikitools.api.APIRequest(site, file_query) query_result = file_request.query() # throws TypeError

It has something to do with api.py around line 289-- you use sets to quickly de-dupe some list(s), but this query tries to dedupe a list of dicts in that block of code, throwing a TypeError because dicts are unhashable.

rblakemesser avatar Feb 03 '14 01:02 rblakemesser

I think I'm getting a similar problem, only mine is on line 300 of api.py:

 <ipython-input-281-2e9a04f51cbe> in get_revisions(title, rvstartid, rvendid, rvcontinue)
      12         params['rvcontinue'] = rvcontinue
      13     request = api.APIRequest(site, params)
 ---> 14     result = request.query()
      15     return result

 /Users/bkarfunkel/anaconda/lib/python2.7/site-packages/wikitools/api.pyc in query(self,    querycontinue)
     154                         raise APIError(data['error']['code'], data['error']['info'])
     155                 if 'query-continue' in data and querycontinue:
 --> 156                         data = self.__longQuery(data)
     157                 return data
     158 

 /Users/bkarfunkel/anaconda/lib/python2.7/site-packages/wikitools/api.pyc in __longQuery(self, initialdata)
     208                         res = req.query(False)
     209                         for type in possiblecontinues:
 --> 210                                 total = resultCombine(type, total, res)
     211                         if 'query-continue' in res:
     212                                 numkeys = len(res['query-continue'].keys())

 /Users/bkarfunkel/anaconda/lib/python2.7/site-packages/wikitools/api.pyc in resultCombine(type, old, new)
     298                                         continue
     299                                 else: # Need to check for possible duplicates for some, this is faster than just iterating over new and checking for dups in ret
 --> 300                                         retset = set([tuple(entry.items()) for entry in ret['query']['pages'][key][type]])
     301                                         newset = set([tuple(entry.items()) for entry in new['query']['pages'][key][type]])
     302                                         retset.update(newset)

 TypeError: unhashable type: 'list'

bkfunk avatar May 11 '14 00:05 bkfunk