`wikimedia.py` - Errors I encountered
ShweataNHegde opened this issue · comments
Shweata N. Hegde commented
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
"""
Shweata N. Hegde commented
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
petermr commented
This looks like a code error from me.
Will debug
…On Fri, Jan 29, 2021 at 10:40 AM ShweataNHegde ***@***.***> wrote:
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFTCSYXVIX5WLFNG2YJR5TS4KGCRANCNFSM4WYQ4XJA>
.
--
Peter Murray-Rust
Founder ContentMine.org
and
Reader Emeritus in Molecular Informatics
Dept. Of Chemistry, University of Cambridge, CB2 1EW, UK