siznax / wptools

Wikipedia tools (for Humans): easily extract data from Wikipedia, Wikidata, and other MediaWikis
MIT License
574 stars 78 forks source link

API warning on get() even with silent=True #118

Closed cmoen closed 6 years ago

cmoen commented 6 years ago

Thanks for wptools. I'm using version 0.4.11 and I'm getting a warning on get() and I'm wondering if there's a way this can be suppressed or otherwise worked-around.

Here's a way to reproduce this warning:

% python3
Python 3.6.5 (default, Mar 30 2018, 06:41:53) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wptools
>>> page = wptools.page(wikibase='Q7754406', silent=True)
>>> page.get()
API warning: {'extracts': {'warnings': 'HTML may be malformed and/or unbalanced and may omit inline images. Use at your own risk. Known problems are listed at https://www.mediawiki.org/wiki/Extension:TextExtracts#Caveats.'}}
<wptools.page.WPToolsPage object at 0x109130630>

In my case, I don't really need extracts, but I would like to get many of the other data points that are captured by get_query() behind the scenes.

Is there a different way I should do my get calls to prevent extracts from outputting all these warnings in my stderr?

siznax commented 6 years ago

Thanks for trying wptools, @cmoen! I'll see if we can adjust our API query to avoid that warning, or provide a way to suppress warning messages.

siznax commented 6 years ago

It looks like your API query is valid, so no change there. But we should always respect the silent flag, even with API warnings, so I made that change. Thanks for opening the issue @cmoen!

cmoen commented 6 years ago

Thanks for looking into this so quickly. I've built my code against the master branch and I can confirm that this seems to be working according to expectations. Thanks again.

peeter-t2 commented 6 years ago

Thanks for the fix, I encountered the same problem. Just a note - upgrading via pip did not help to correct this, but replacing the files from master fixed it for me too.

siznax commented 6 years ago

FYI, I made point release v0.4.12 for this fix, so you should be able to pip install --upgrade wptools for this now.

Thanks for the reminder @peeter-t2!

peeter-t2 commented 6 years ago

Thanks!!