Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wikimedia.py - Errors I encountered #24

Open
ShweataNHegde opened this issue Jan 29, 2021 · 2 comments
Open

wikimedia.py - Errors I encountered #24

ShweataNHegde opened this issue Jan 29, 2021 · 2 comments

Comments

@ShweataNHegde
Copy link
Collaborator

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
        """
@ShweataNHegde
Copy link
Collaborator Author

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
Copy link
Owner

petermr commented Jan 29, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants