You are browsing a read-only backup copy of Wikitech. The live site can be found at wikitech.wikimedia.org
Help talk:Toolforge/My first Flask OAuth tool
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)
- 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)
pipprogram 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'
$HOME/www/python/venv/bin/pipis in the default search path. --BryanDavis (talk) 05:21, 6 February 2017 (UTC)
"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
- 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)
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)
Making the tool HTTPS only
Using toolforge helper library:
from flask import Flask import toolforge app = Flask(__name__) app.before_request(toolforge.redirect_to_https)
- 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)
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)
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)
- 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)
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)
- If "developer mode" means https://flask.palletsprojects.com/en/1.1.x/server/, there is not an easy way to do that today with the webservice command. It should be possible to accomplish the
flask runmethod 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-configuredto 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)
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
OAUTH_MWURIsetting 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: https://meta.wikimedia.org/w/index.php".
- Your mapping of the MediaWiki OAuth terminology to the tutorial's terminology is correct. --BryanDavis (talk) 16:14, 29 June 2020 (UTC)