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

Client:ask broken ? #153

Closed
ghost opened this issue May 6, 2017 · 5 comments
Closed

Client:ask broken ? #153

ghost opened this issue May 6, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented May 6, 2017

Hi all,

as it is , I cannot get Client:ask to work ,

For example, test it on Semantic Mediawiki Sandbox

site=mwclient.Site(('https','sandbox.semantic-mediawiki.org'),'/w/')
query="[[Has email::%2B]]|%3FLabel" 
# see https://sandbox.semantic-mediawiki.org/wiki/Sp%C3%A9cial:Parcourir/:Azure  : this page should be returned by ask
# + note that the arguments must be url encoded (see https://www.semantic-mediawiki.org/wiki/Ask_API )
res=site.ask(query)
res.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/mwclient/client.py", line 960, in ask
    for result in results['query']['results']:

The trouble is : there is no "query" field in the response returned by site.ask() , the api calls returns an error

But you can see the query results here :

https://sandbox.semantic-mediawiki.org/w/api.php?action=ask&query=[[Has%20email::%2B]]|%3FLabel&format=json

Cheers

PS : what is the use of the Title parameter in Client.ask() ?

MB

@ghost
Copy link
Author

ghost commented May 6, 2017

OK, in client.py

960            results = self.raw_api('ask', query='{query}|offset={offset}'.format(
961                     query=query, offset=offset, http_method='GET'), **kwargs)

should probably be

960            results = self.raw_api('ask', query='{query}|offset={offset}'.format(
961                     query=query, offset=offset) , http_method='GET', **kwargs)

i.e. closing parenthesis after "offset" not "''GET'"

Now it is working with :

  • query ="[[Has email::%2B]]"

but not with

  • query="[[Has email::%2B]]|%3FLabel"
>>> offset =0
>>> kwargs={}
>>> query="[[Has email::%2B]]|%3FLabel"
>>> results = site.raw_api('ask', query='{query}|offset={offset}'.format(query=query, offset=offset) , http_method='GET', **kwargs)
>>> results
{u'error': {u'query': [u'La partie \xab %3FLabel \xbb de la requ\xeate n\u2019a pas \xe9t\xe9 comprise. Les r\xe9sultats peuvent \xeatre inattendus.']}}
>>> query="[[Has email::%2B]]"
>>> results = site.raw_api('ask', query='{query}|offset={offset}'.format(query=query, offset=offset) , http_method='GET', **kwargs)
>>> results
{u'query': {u'serializer': u'SMW\\Serializers\\QueryResultSerializer', u'version': 2, u'meta': {u'count': 0, u'source': u'', u'time': u'0.000213', u'hash': u'8abf92b9a496fa12811f646f040f3025', u'offset': 0}, u'results': [], u'printrequests': [{u'typeid': u'_wpg', u'redi': u'', u'mode': 2, u'key': u'', u'label': u''}]}}
>>>

@ghost
Copy link
Author

ghost commented May 6, 2017

OK, all is working now if :

  1. the closing parenthesis is put at the right place ( see Client:ask broken ? #153 (comment) )
  2. and you don't encode arguments of the semantic query before calling ask

@danmichaelo
Copy link
Member

Thx for looking into this! Would you mind opening a pull request for the commits?

@ghost
Copy link
Author

ghost commented May 10, 2017 via email

@ghost
Copy link
Author

ghost commented May 10, 2017 via email

danmichaelo pushed a commit that referenced this issue May 10, 2017
Misplaced parenthesis
danmichaelo pushed a commit that referenced this issue May 10, 2017
Misplaced parenthesis
danmichaelo pushed a commit that referenced this issue May 11, 2017
Misplaced parenthesis
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

1 participant