petermr / dictionary

Collection of Wikidata-based dictionaries for scientific annotation and searching

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`wikimedia.py` - Errors I encountered

ShweataNHegde opened this issue · comments

I ran wikimedia.py from PyCharm. The default query worked fine. However, when I changed the query to something else, I get the following errors:

help for Wikimedia routines NYI
req <Response [400]>
Traceback (most recent call last):
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 233, in <module>
    main()
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 220, in main
    df0 = wm.submit_process_sparql(query=TEST_QUERY)
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 160, in submit_process_sparql
    query_results_dict = wm.post_sparql(query)
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 111, in post_sparql
    return self.post_request(WIKIDATA_QUERY_URL, query, format)
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 121, in post_request
    return req.json() if format == JSON else None
  File "C:\Users\shweata\anaconda3\lib\site-packages\requests\models.py", line 898, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\shweata\anaconda3\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\shweata\anaconda3\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\shweata\anaconda3\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

For reference, the query that I input:

TEST_QUERY = """
        SELECT 
         ?item ?itemLabel ?GRINid ?itemAltLabel
        WHERE {
          ?item wdt:P31 wd:Q16521.
          ?item wdt:P105 wd:Q34740.
          ?item wdt:P1421 ?GRINid.
          }
          SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
        }
#        LIMIT 3
        """

There was an error in the query. An extra { symbol. Now I get a different error:

help for Wikimedia routines NYI
req <Response [200]>
Cannot parse {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q130337'}
Traceback (most recent call last):
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 234, in <module>
    main()
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 221, in main
    df0 = wm.submit_process_sparql(query=TEST_QUERY)
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 172, in submit_process_sparql
    return self.create_data_frame_from_bindings(bindings, colhead_array)
  File "C:/Users/shweata/dictionary/pythoncode/pyamidict/editor/wikimedia.py", line 189, in create_data_frame_from_bindings
    new_row_dict[colhead] = val
UnboundLocalError: local variable 'val' referenced before assignment

Process finished with exit code 1