Page MenuHomePhabricator

Provide sensible information when the Requests dependency is missing for Pywikibot
Closed, DeclinedPublic

Description

Right now if someone tries to run Pywikibot and doesn't have Requests installed you'll just get "ImportError: No module named requests Python module request is required. Try running 'pip install request'". This is a source of confusion, see https://www.wikidata.org/wiki/Wikidata:Project_chat#Pywikibot (https://www.wikidata.org/w/index.php?title=Wikidata:Project_chat&oldid=237132448#Pywikibot).

We should modify the code a bit that if Requests is missing and a user fires up Pywikibot, the user will get some nice commandline output explaining that Pywikibot requires the library requests (with a link to http://docs.python-requests.org/en/latest/) and that it needs to be installed first. Probably the suggestion to run "pip install request" or to have a look at http://docs.python-requests.org/en/latest/user/install/#install if that doesn't work.

Event Timeline

Multichill raised the priority of this task from to Medium.
Multichill updated the task description. (Show Details)
Multichill added a subscriber: Multichill.
Restricted Application added a project: Documentation. · View Herald TranscriptJul 28 2015, 7:04 PM
Restricted Application added subscribers: pywikibot-bugs-list, Aklapper. · View Herald Transcript
XZise added a subscriber: XZise.Jul 29 2015, 10:37 AM

Well it already suggests to run pip install requests. I'd actually prefer (if we link to something) to link something like https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation. The main issue I see is that we have currently three different setups:

  • compat
  • core 2.0 using httplib2
  • core master using requests

So that page probably must be updated and it should separate between mandatory dependencies (e.g. also the future package on Python 2.6 and maybe unicodedata2 on 2.6.6 depending on T102461) and optional dependencies.

jayvdb added a subscriber: jayvdb.Jul 30 2015, 12:04 PM

@Multichill, if the user uses pwb.py, the requests error message is the same as the previous httplib2 error message:

https://github.com/wikimedia/pywikibot-core/commit/952665acaa9ab2dd1a78cb4a935f3b5743941913#diff-f15f62388b2fa48d5a3f9f09dbafceffL143

The change was here: https://gerrit.wikimedia.org/r/#/c/213977/

As xZise points out, the code is already giving basic instructions.
IMO 'code' the goes far enough.
pip is now the official package installer, and was backported to be part of the official Python 2.7.10 distribution.

We also have a requirements.txt that can be used with pip, and python setup.py install also works.

The use of requirements.txt is mentioned on https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation#Dependencies . However that page is a awful mess.

jayvdb changed the task status from Open to Stalled.Aug 19 2015, 6:00 AM

Per previous comment, the code already does most of what was requested.
as an aside, https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation has been cleaned up a lot.

I am not sure that adding URL 'http://docs.python-requests.org/en/latest/' to the error message is better than telling people to use pip install requests or pip install -r requirements.txt.
So I am tempted to close this as Declined or Invalid, but open to suggestions/opinons.

Dvorapa added a subscriber: Dvorapa.EditedJun 1 2018, 4:08 PM

Current py2 implementation does not seem ok to me:

$ python2 pwb.py shell
Traceback (most recent call last):
  File "pwb.py", line 151, in <module>
    "Try running 'pip install requests'.".format(e))
ImportError: No module named requests
Python module 'requests' is required.
Try running 'pip install requests'.
Xqt closed this task as Declined.Jun 1 2018, 7:59 PM

Why do you assume that this is not ok? shell.py preloads pywikibot by default except you choose to opt out this behavior by an -noimport option. pywikibot.py tries to import requests and if it fails that hint is printed.

Dvorapa added a comment.EditedJun 1 2018, 8:08 PM

The information about missing requests is written into 6 lines, which is not ok at all. Basically it says:

Line 1: There is an error
Line 2: Error on line xyz in pwb.py
Line 3: Try this to install requests
Line 4: Requests missing
Line 5: Requests missing
Line 6: Try this to install requests

I would expect max 5 lines:

Traceback (most recent call last):
  File "pwb.py", line xyz, in <module>
    raise RequestsError(e)
ImportError: No module named requests
Install it by running 'pip install requests'.
Line 1: There is an error
Line 2: Error on line xyz in pwb.py
Line 3: Usual line of code not duplicating messages above or below
Line 5: Requests missing
Line 6: Try this to install requests