Rendered with Parsoid

Help talk:Toolforge/My first Flask OAuth tool

From Wikitech
Jump to navigation Jump to search
This talk page is not a Cloud VPS or Toolforge support forum. Contact information for Cloud VPS and Toolforge can be found at Help:Cloud Services communication.


Of what host is this talking about?

tools.bub@tools-bastion-01:~/public_html/BUB/bot$ pip install --user internetarchive
The program 'pip' is currently not installed. To run 'pip' please ask your administrator to install the package 'python-pip'

--Nemo 11:37, 1 June 2015 (UTC)Reply[reply]

Nemo bis, is pip still not installed? That sounds like a bug in the environment. Alternatively is the command virtualenv installed? John Vandenberg (talk) 21:04, 21 December 2015 (UTC)Reply[reply]
The pip program is purposefully not installed globally on the bastions or other Tool Labs servers. In the tutorial, use of pip ... commands assumes that you have already activated the virtual environment for your shell session by running source $HOME/www/python/venv/bin/activate. Sourcing that script alters your shell sessions' $PATH so that $HOME/www/python/venv/bin/pip is in the default search path. --BryanDavis (talk) 05:21, 6 February 2017 (UTC)Reply[reply]

"Address already in use"

I am getting "socket.error: [Errno 98] Address already in use". I have tried "webservice2 uwsgi-python stop" and "webservice2 uwsgi-python restart" as well as "webservice uwsgi-python stop". Nothing seems to help. With "ps -ef | grep scholia" I see three relevant lines. These processes are owned by root. Here is a few messages from

   (venv)tools.scholia@tools-bastion-03:~$ webservice2 uwsgi-python start
   Your job is already running
   (venv)tools.scholia@tools-bastion-03:~$ webservice2 status
   Your webservice is not running
   (venv)tools.scholia@tools-bastion-03:~$ webservice2 uwsgi-python restart
   Restarting webservice...............
   (venv)tools.scholia@tools-bastion-03:~$ webservice2 status
   Your webservice is not running

It seems that I got started processes I cannot stop. Finn Årup Nielsen (fnielsen) (talk) 17:04, 10 October 2016 (UTC)Reply[reply]

For readers from the future (hi!) we worked through this on irc. The hanging jobs were in shutdown state but not exiting so they were force killed using sudo qdel $JOBID. The "Address already in use" error seemed to be only semi-related and instead caused by incorrect PYTHONPATH settings which led to the wsgi process crashing. --BryanDavis (talk) 17:43, 12 October 2016 (UTC)Reply[reply]

Major rewrite of content

I have boldy rewritten much of the content and moved the page from Help:Tool Labs/Python application stub to Help:Tool Labs/My first Flask OAuth tool. Some more things I would like to see added are listed in task T134494. --BryanDavis (talk) 05:16, 6 February 2017 (UTC)Reply[reply]

Making the tool HTTPS only

Using toolforge helper library:

from flask import Flask
import toolforge

app = Flask(__name__)

Is this beginner enough to mention in the tutorial? Or should it just be a footnote? legoktm (talk) 07:54, 26 August 2017 (UTC)Reply[reply]

I think either would be fine, but it might be easiest to add in as a "what next" step. That could be as easy as linking to User:Legoktm/toolforge library. --BryanDavis (talk) 17:51, 26 August 2017 (UTC)Reply[reply]
Yes Done I added Bryan’s suggestion for now. --Lucas Werkmeister (WMDE) (talk) 09:29, 19 June 2018 (UTC)Reply[reply]

Very useful

As a Flask and Toolforge newbie this guide was extremely helpful to getting set up. Thanks to all who wrote it (from the history, Little green rosetta, Merlijn van Deen, and BryanDavis)! Samwalton9 (talk) 14:43, 10 November 2017 (UTC)Reply[reply]

virtualenv not present in kubernetes container

@APerson:, I feel that edit that you made about using virtualenv is misleading. There is no virtualenv script installed inside the Kubernetes python container. I think that it is possible that the command you provided will work from a Toolforge bastion, but even then the generated venv may be subtlety incompatible with the version of Python that is used in the Kubernetes containers.

$ webservice --backend=kubernetes python shell
$ virtualenv $HOME/www/python/venv -p /usr/bin/python3
bash: virtualenv: command not found

I did not want to revert without some discussion here however in case there are other issues that I have missed. Maybe the instruction to perform the commands from within a Kubernetes managed container are not prominent enough? --BryanDavis (talk) 21:47, 7 October 2018 (UTC)Reply[reply]

BryanDavis, oh, I see. Yes, I evidently missed the first command. I was going off this discussion on the WMF Phabricator where the command I used was recommended (I found it by searching for the error message I got when trying the normal command). I have amended the section to indicate that you should only get the error message I got if you forgot to run the first command. I'm also fine with removing the paragraph all together if it might confuse users. Thanks for pointing this out! APerson (talk!) 05:31, 8 October 2018 (UTC)Reply[reply]

Developer mode

Hi, is there a possibility to use the advantages of the developer mode on Toolforge? It would be helpful, if Flask would recognize changed files. At the moment, I have to restart the webservice again and again to reflect these changes. Any ideas? --FNDE (talk) 20:40, 14 July 2019 (UTC)Reply[reply]

If "developer mode" means, there is not an easy way to do that today with the webservice command. It should be possible to accomplish the flask run method using a custom deployment as described in Help:Toolforge/Kubernetes#Kubernetes_continuous_jobs, but that would be a very advanced thing to add to a "my first X" tutorial. Adding a touch-reload option to a $HOME/www/python/uwsgi.ini config file and then using touch the-path-you-configured to trigger a reload might get close to doing what you want, but I have not tried that personally. See Help:Toolforge/Web#Default_uwsgi_configuration for a bit more info on $HOME/www/python/uwsgi.ini. --BryanDavis (talk) 00:17, 15 July 2019 (UTC)Reply[reply]


What is app.config['OAUTH_MWURI'] in the last code? How can I find it? Also when I register of a new OAuth consumer, it says You have been assigned a consumer token of aaaaaaaaaaaaaaaaaaa and a secret token of bbbbbbbbbbbbbb Please record these for future reference. Am I getting it right that in config.yaml it should be

  • CONSUMER_KEY: aaaaaaaaaaaaaaaaaaa
  • CONSUMER_SECRET: bbbbbbbbbbbbbb

? Thank you very much!--Ashot1997 (talk) 16:32, 27 June 2020 (UTC)Reply[reply]

The OAUTH_MWURI setting seems to have disappeared from the tutorial body, but it is documented in the related git repository. The default value should be something like "OAUTH_MWURI:".
Your mapping of the MediaWiki OAuth terminology to the tutorial's terminology is correct. --BryanDavis (talk) 16:14, 29 June 2020 (UTC)Reply[reply]
Hi, BryanDavis. Thank you very much for your answer ^_^.--Ashot1997 (talk) 04:47, 2 July 2020 (UTC)Reply[reply]

Installed packages in env report ModuleNotFoundError

After installing packages by `running pip install -r path-to-requirements.ext`, it completes cleanly. However, restarting the webservice reports that these modules are not found causing the application to fail with an internal server error. This is something I have been doing long before now but it seems to fail all the time. Am i missing something this time around?

PS: The said tool is the `isa-dev` tool on which we want to test new features and bug fixes before deploying to the live tool `isa` Eugene233 (talk) 01:10, 12 February 2024 (UTC)Reply[reply]

@Eugene233 Your virtual environment was created for Python 3.11 but you're trying to run the web service on Python 3.9. Try completely stopping the web service, updating service.template for 3.11, and then starting it. Taavi (talk!) 08:14, 12 February 2024 (UTC)Reply[reply]