Page MenuHomePhabricator

A MediaWiki API error occurred: The authorization headers in your request are not valid for metawiki
Closed, InvalidPublic

Description

I have tried to deploy tool-my-first-flask-oauth-tool on my tool qrcode-generator. These were the steps that I followed.

Jay-Prakash:~ administrator$ ssh jayprakash12345@login.tools.wmflabs.org
jayprakash12345@tools-sgebastion-07:~$ become qrcode-generator
tools.qrcode-generator@tools-sgebastion-07:~$ mkdir -p $HOME/www/python
tools.qrcode-generator@tools-sgebastion-07:~$ git clone https://phabricator.wikimedia.org/source/tool-my-first-flask-oauth-tool.git   $HOME/www/python/src
tools.qrcode-generator@tools-sgebastion-07:~$ webservice --backend=kubernetes python shell
tools.qrcode-generator@interactive:~$ touch $HOME/www/python/src/config.yaml
tools.qrcode-generator@interactive:~$ chmod u=rw,go= $HOME/www/python/src/config.yaml
tools.qrcode-generator@interactive:~$ cat > $HOME/www/python/src/config.yaml << EOF
SESSION_COOKIE_PATH: /qrcode-generator
SECRET_KEY: $(python -c "import os; print repr(os.urandom(24))")
CONSUMER_KEY: Key_from_Meta
CONSUMER_SECRET: Secret_from_Meta
EOF
tools.qrcode-generator@tools-sgebastion-07:~$ webservice --backend=kubernetes python start

Now The tool has up. But When I tried to login, I get the Internal Server Error. I get these logs from uwsgi.log

*** Operational MODE: preforking ***
mounting /data/project/qrcode-generator/www/python/src/app.py on /qrcode-generator
WSGI app 0 (mountpoint='/qrcode-generator') ready in 8 seconds on interpreter 0x200a330 pid: 1 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1)
spawned uWSGI worker 1 (pid: 8, cores: 1)
spawned uWSGI worker 2 (pid: 9, cores: 1)
spawned uWSGI worker 3 (pid: 10, cores: 1)
spawned uWSGI worker 4 (pid: 11, cores: 1)
[pid: 8|app: 0|req: 1/1] 192.168.180.0 () {40 vars in 1212 bytes} [Thu Jun 20 08:34:43 2019] GET /qrcode-generator/ => generated 4364 bytes in 44 msecs (HTTP/1.1 200) 2 headers in 81 bytes (1 switches on core 0)
[pid: 9|app: 0|req: 1/2] 192.168.180.0 () {42 vars in 1262 bytes} [Thu Jun 20 08:34:44 2019] GET /qrcode-generator/static/site.css => generated 32 bytes in 20 msecs via sendfile() (HTTP/1.1 200) 8 headers in 303 bytes (0 switches on core 0)
[pid: 8|app: 0|req: 2/3] 192.168.180.0 () {40 vars in 1255 bytes} [Thu Jun 20 08:34:49 2019] GET /qrcode-generator/login => generated 567 bytes in 106 msecs (HTTP/1.1 302) 5 headers in 561 bytes (1 switches on core 0)
[2019-06-20 08:34:53,764] ERROR in app: OAuth autnetication failed
Traceback (most recent call last):
  File "/data/project/qrcode-generator/www/python/src/app.py", line 98, in oauth_callback
    app.config['OAUTH_MWURI'], consumer_token, access_token)
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/mwoauth/functions.py", line 252, in identify
    "A MediaWiki API error occurred: {0}".format(resp['message']))
mwoauth.errors.OAuthException: A MediaWiki API error occurred: The authorization headers in your request are not valid for metawiki
[2019-06-20 08:34:53,778] ERROR in app: Exception on /oauth-callback [GET]
Traceback (most recent call last):
  File "/data/project/qrcode-generator/www/python/src/app.py", line 98, in oauth_callback
    app.config['OAUTH_MWURI'], consumer_token, access_token)
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/mwoauth/functions.py", line 252, in identify
    "A MediaWiki API error occurred: {0}".format(resp['message']))
mwoauth.errors.OAuthException: A MediaWiki API error occurred: The authorization headers in your request are not valid for metawiki

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/data/project/qrcode-generator/www/python/venv/lib/python3.4/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/data/project/qrcode-generator/www/python/src/app.py", line 102, in oauth_callback
    flask.flask(u'OAuth authentication failed.')
AttributeError: 'module' object has no attribute 'flask'
[pid: 11|app: 0|req: 1/4] 192.168.180.0 () {42 vars in 1801 bytes} [Thu Jun 20 08:34:53 2019] GET /qrcode-generator/oauth-callback?oauth_verifier=a7f5178d9aa812e5a55fe9719cd8b235&oauth_token=3cc8f34b3e2d6d2b1f0968614876ef3c => generated 290 bytes in 218 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

@bd808 Please help me as you are the maintainer of my-first-flask-oauth-tool. So you will maybe have the experience of deploying this tool. I am asking because as a part of my GSoC project. I have developed a tool qrcode-generator and I am getting the same error of The authorization headers in your request are not valid for metawiki.

ccing my mentor @srishakatux

There is another exception occurred which will be fixed just fixing typo flask.flask to flask.flash in tool-my-first-flask-oauth-tool/browse/master/app.py

@bd808 If there is any other channel you recommend, we should ask this question, let us know! As @Jayprakash12345 is getting the same error with the "my-first-flask.." tutorial, we thought it has something to do with Toolforge, and you might have an answer.

mwoauth.errors.OAuthException: A MediaWiki API error occurred: The authorization headers in your request are not valid for metawiki probably means that something is not quite right with your CONSUMER_KEY and/or CONSUMER_SECRET settings.

The values you show in the bug report are placeholder values. That is good, because you should not be sharing the real values that you received when you signed up at https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration with anyone. You should double check the real values you are using in the $HOME/www/python/src/config.yaml file against the data you have about your consumer on meta. https://www.mediawiki.org/wiki/OAuth/For_Developers may have some additional tips for debugging.

Thank you @bd808 and @srishakatux Ji, I have figure out the problem. Using Python_command-line_client_using_mwoauth, I have found that It is giving the same error. But instead of metawiki It was enwiki. So the problem is that if you select a specific project (in my case, It was common.wikimedia.org) instead of * (All projects) in OAuthConsumerRegistration. then you have to handshake with that project instead of CentralWiki. Now I have checkout my tool and start web service for some time. It worked well. And upload the File:Bnwikisource-বড়দিদি.svg on commons.

Thank you :)