Page MenuHomePhabricator

pwb.py cannot login to self-hosted mediawiki site
Closed, InvalidPublic

Description

Steps to reproduce:

  • python pwb.py login, after creating family and user files
  • get error:
peter@peter-BHYVE2:~/NetShare/core$ python3 pwb.py login
WARNING: Non-JSON response received from server finwiki:en; the server may be down.
WARNING: Waiting 5 seconds before retrying.
WARNING: Non-JSON response received from server finwiki:en; the server may be down.
WARNING: Waiting 10 seconds before retrying.
^CTraceback (most recent call last):
  File "/home/peter/NetShare/core/pywikibot/data/api.py", line 1999, in submit
    result = json.loads(rawdata)
  File "/usr/lib/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 251, in <module>
    if not main():
  File "pwb.py", line 244, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 115, in run_python_file
    main_mod.__dict__)
  File "./scripts/login.py", line 196, in <module>
    main()
  File "./scripts/login.py", line 179, in main
    site.login(sysop, autocreate=autocreate)
  File "/home/peter/NetShare/core/pywikibot/site.py", line 2056, in login
    self.getuserinfo(force=True)
  File "/home/peter/NetShare/core/pywikibot/site.py", line 2154, in getuserinfo
    uidata = uirequest.submit()
  File "/home/peter/NetShare/core/pywikibot/data/api.py", line 1906, in submit
    self._add_defaults()
  File "/home/peter/NetShare/core/pywikibot/data/api.py", line 1697, in _add_defaults
    self.site.version()) >= MediaWikiVersion('1.25wmf5')):
  File "/home/peter/NetShare/core/pywikibot/site.py", line 2737, in version
    expiry=1).split(' ')[1]
  File "/home/peter/NetShare/core/pywikibot/site.py", line 1659, in get
    preloaded = self._get_general(key, expiry)
  File "/home/peter/NetShare/core/pywikibot/site.py", line 1605, in _get_general
    default_info = self._get_siteinfo(props, expiry)
  File "/home/peter/NetShare/core/pywikibot/site.py", line 1530, in _get_siteinfo
    data = request.submit()
  File "/home/peter/NetShare/core/pywikibot/data/api.py", line 2368, in submit
    self._data = super(CachedRequest, self).submit()
  File "/home/peter/NetShare/core/pywikibot/data/api.py", line 2017, in submit
    self.wait()
  File "/home/peter/NetShare/core/pywikibot/data/api.py", line 2225, in wait
    pywikibot.sleep(self.retry_wait)
  File "/home/peter/NetShare/core/pywikibot/__init__.py", line 1335, in sleep
    time.sleep(secs)
KeyboardInterrupt
<class 'KeyboardInterrupt'>
CRITICAL: Closing network session.
  • Website is confirmed online, can be seen inside and outside network
  • API is located at wiki.[REDACTED].com/api.php and is functional
  • api sandbox functional, can create text, edit, etc.
  • Manual python commands using this sample code is successful, I can upload or query the site as needed. This also includes logging in.
  • changing family file to http or https has no effect on error
  • changing family file to http://wiki.[REDACTED].com/api.php has no effect on error
  • manually creating family file has no effect (see comments)

Results of python pwb.py version:

BHYVE2:~/NetShare/core$ python pwb.py version
Skipped '/home/peter/NetShare/core/user-config.py': owned by someone else.
family and mylang are not set.
Defaulting to family='test' and mylang='test'.
Pywikibot: [https] r-pywikibot-core.git (29f503e, g1, 2018/06/06, 04:17:59, OUTDATED)
Release version: 3.1.dev0
requests version: 2.18.4
  cacerts: /home/peter/.local/lib/python3.6/site-packages/certifi/cacert.pem
    certificate test: ok
Python: 3.6.3 (default, Oct  3 2017, 21:45:48)
[GCC 7.2.0]
PYWIKIBOT2_DIR: Not set
PYWIKIBOT2_DIR_PWB:
PYWIKIBOT2_NO_USER_CONFIG: Not set
Config base dir: /home/peter/NetShare/core

Event Timeline

Sc4s2cg updated the task description. (Show Details)
Sc4s2cg updated the task description. (Show Details)
Sc4s2cg updated the task description. (Show Details)

I'm not into Pywikibot but I wonder if

Skipped '/home/peter/NetShare/core/user-config.py': owned by someone else.

is relevant. Have you tried fixing the file permissions?

Which MediaWiki version is used?

I'm not into Pywikibot but I wonder if

Skipped '/home/peter/NetShare/core/user-config.py': owned by someone else.

is relevant. Have you tried fixing the file permissions?

@Aklapper is correct, it seems pywikibot can not access user-config.py file, in which you should specify your family, code and username to access the wiki.

@Aklapper MediaWiki is 1.30.0 using Ubuntu 17.10

@Dvorapa Hmm, is the problem then pywikibot incorrectly sets the permissions after creating the user-config.py wiki file?

I just tried again with a new install:

  • extract core.tar
  • python3 generate_family_file.py
  • python3 pwb.py login
  • ls -l
  • user-config.py default permission: -rw-rw-r--

What should the permission be? 777 results in pywikibot ignoring the user-config.py file because it is writeable.

Did you run python3 generate_user_files.py? Or how do you create your user-config.py file? Is the contents of the file correct? In which folder do you store the file?

What should the permission be? 777 results in pywikibot ignoring the user-config.py file because it is writeable.

Ideally 660 as you already have

Also please make sure you have an updated version as today there was a major issue fixed with generate_user_files.py

I created the user-config.py file using the initial setup via "python3 pwb.py login". It prompts for the creation of the file. The contents were correct. It is in the core folder.

So you have to run login twice, right? Once for creating user-config.py and second time for logging in.

Please also share values of mylang, myfamily, usernames in user-config.py, maybe also your famwiki family file created. If there is no problem in those, then the problem could be in a wiki configuration.

Also try to run pywikibot from a different computer, sometimes it causes a trouble.

I changed permissions of user-config.py using sudo chmod 666, but it is still complaining that the file is writeable:

peter@peter-BHYVE2:~/NetShare/core$ sudo chmod 666 user-config.py
[sudo] password for peter:
peter@peter-BHYVE2:~/NetShare/core$ python3 pwb.py login
Skipped '/home/peter/NetShare/core/user-config.py': writeable by others.
family and mylang are not set.
Defaulting to family='test' and mylang='test'.
Traceback (most recent call last):
  File "/home/peter/NetShare/core/pywikibot/login.py", line 114, in __init__
    self.username = self.username or family_usernames['*']
KeyError: '*'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 251, in <module>
    if not main():
  File "pwb.py", line 244, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 115, in run_python_file
    main_mod.__dict__)
  File "./scripts/login.py", line 196, in <module>
    main()
  File "./scripts/login.py", line 179, in main
    site.login(sysop, autocreate=autocreate)
  File "/home/peter/NetShare/core/pywikibot/site.py", line 2089, in login
    user=self._username[sysop])
  File "/home/peter/NetShare/core/pywikibot/tools/__init__.py", line 1446, in wrapper
    return obj(*__args, **__kw)
  File "/home/peter/NetShare/core/pywikibot/login.py", line 122, in __init__
    'wiki_code': self.site.code})
pywikibot.exceptions.NoUsername: ERROR: Username for test:test is undefined.
If you have an account for that site, please add a line to user-config.py:

usernames['test']['test'] = 'myUsername'
<class 'pywikibot.exceptions.NoUsername'>
CRITICAL: Closing network session.

So you have to run login twice, right? Once for creating user-config.py and second time for logging in.

Yes, exactly.

Also please make sure you have an updated version as today there was a major issue fixed with generate_user_files.py

I redownloaded from here, but am still having to manually edit the user-config.py. Is there a different source I should be using?

Also try to run pywikibot from a different computer, sometimes it causes a trouble.

Tried using both SSH (putty) to Ubuntu to run pwb.py, and local (windows). For Ubuntu I got permission problems (the code above), in Windows I get:

PS C:\Users\Peter\Downloads\core> python pwb.py login
WARNING: Non-JSON response received from server famwiki:en; the server may be down.
WARNING: Waiting 5 seconds before retrying.
Traceback (most recent call last):
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 1999, in submit
    result = json.loads(rawdata)
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 251, in <module>
    if not main():
  File "pwb.py", line 244, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 115, in run_python_file
    main_mod.__dict__)
  File ".\scripts\login.py", line 196, in <module>
    main()
  File ".\scripts\login.py", line 179, in main
    site.login(sysop, autocreate=autocreate)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 2056, in login
    self.getuserinfo(force=True)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 2154, in getuserinfo
    uidata = uirequest.submit()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 1906, in submit
    self._add_defaults()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 1697, in _add_defaults
    self.site.version()) >= MediaWikiVersion('1.25wmf5')):
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 2737, in version
    expiry=1).split(' ')[1]
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 1659, in get
    preloaded = self._get_general(key, expiry)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 1605, in _get_general
    default_info = self._get_siteinfo(props, expiry)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 1530, in _get_siteinfo
    data = request.submit()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 2368, in submit
    self._data = super(CachedRequest, self).submit()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 2017, in submit
    self.wait()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 2225, in wait
    pywikibot.sleep(self.retry_wait)
  File "C:\Users\Peter\Downloads\core\pywikibot\__init__.py", line 1335, in sleep
    time.sleep(secs)
KeyboardInterrupt
<class 'KeyboardInterrupt'>
CRITICAL: Closing network session.

Please also share values of mylang, myfamily, usernames in user-config.py, maybe also your famwiki family file created. If there is no problem in those, then the problem could be in a wiki configuration.

user-config.py: https://pastebin.com/MhYV0UcN
famwiki_family.py: https://pastebin.com/xBFG6G1q

I've never seen filemode issues like this with pwb, maybe you should try a different computer as I suggested earlier. The family file seems ok to me, the user file probably also ok. Do you use botpasswords or just usual password? Also try to log in without a password file set (it will ask for password).

If you don't have an access to some other computer, try to access your wiki using https://paws.wmflabs.org/paws/hub/login PAWS. You will need Wikimedia account to log in, but after that you could run Pywikibot from Wikimedia servers and try to access your wiki "from outside". See https://www.mediawiki.org/wiki/Manual:Pywikibot/PAWS for more details. The steps after accessing the Terminal are the same there

If you don't have an access to some other computer, try to access your wiki using https://paws.wmflabs.org/paws/hub/login PAWS. You will need Wikimedia account to log in, but after that you could run Pywikibot from Wikimedia servers and try to access your wiki "from outside". See https://www.mediawiki.org/wiki/Manual:Pywikibot/PAWS for more details. The steps after accessing the Terminal are the same there

PAWS is not a great idea for using pywikibot with external mediawikis at this point as it will pre-set oauth authentication with wikimedia wikis.

I changed permissions of user-config.py using sudo chmod 666, but it is still complaining that the file is writeable:

Please use chmod 660 pywikibot verifies the others group and fails if it can write to it.

I was using botpasswords, but just tried using normal login but same issue. So from what I can tell:

  • Ubuntu: permission issues won't let pyb.py access user-config.py. 666 and 777 permissions it says are too broad (first traceback in above post). @Chicocvenancio 660 permissions worked, now it has the same traceback as windows.
  • Windows: no permission issues, it can access user-config.py but does not get a JSON response from mediawiki.

Traceback from pwb.py trying to login:

PS C:\Users\Peter\Downloads\core> python pwb.py login
WARNING: Non-JSON response received from server famwiki:en; the server may be down.
WARNING: Waiting 5 seconds before retrying.
WARNING: Non-JSON response received from server famwiki:en; the server may be down.
WARNING: Waiting 10 seconds before retrying.
Traceback (most recent call last):
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 1999, in submit
    result = json.loads(rawdata)
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Peter\AppData\Local\Programs\Python\Python36-32\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "pwb.py", line 251, in <module>
    if not main():
  File "pwb.py", line 244, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "pwb.py", line 115, in run_python_file
    main_mod.__dict__)
  File ".\scripts\login.py", line 196, in <module>
    main()
  File ".\scripts\login.py", line 179, in main
    site.login(sysop, autocreate=autocreate)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 2056, in login
    self.getuserinfo(force=True)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 2154, in getuserinfo
    uidata = uirequest.submit()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 1906, in submit
    self._add_defaults()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 1697, in _add_defaults
    self.site.version()) >= MediaWikiVersion('1.25wmf5')):
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 2737, in version
    expiry=1).split(' ')[1]
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 1659, in get
    preloaded = self._get_general(key, expiry)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 1605, in _get_general
    default_info = self._get_siteinfo(props, expiry)
  File "C:\Users\Peter\Downloads\core\pywikibot\site.py", line 1530, in _get_siteinfo
    data = request.submit()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 2368, in submit
    self._data = super(CachedRequest, self).submit()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 2017, in submit
    self.wait()
  File "C:\Users\Peter\Downloads\core\pywikibot\data\api.py", line 2225, in wait
    pywikibot.sleep(self.retry_wait)
  File "C:\Users\Peter\Downloads\core\pywikibot\__init__.py", line 1335, in sleep
    time.sleep(secs)
KeyboardInterrupt
<class 'KeyboardInterrupt'>
CRITICAL: Closing network session.

I see. I still feel like there is a broken connection between pwb and api. In your family file maybe you can try to set apipath and path parameters directly. I'm running out of ideas.

Yeah, I tried editing the families path directly:

Configuration parameters:
url = https://wiki.[REDACTED.com]/index.php
name = famwiki

to

Configuration parameters:
url = https://wiki.[REDACTED.com]/api.php
name = famwiki

Yeah, I'm running out of ideas as well. I went ahead and ran a manual python script again but it ran successfully. It logged in and edited a page. Would you care to test if I gave you access to the mediawiki?

Edit: to clarify, pwb is able to any of the default mediawikis (like wikivoyage, wikipedia). Just not the custom added ones (mine).

url = https://wiki.[REDACTED.com]/api.php

I meant apipath = 'https://wiki.[REDACTED.com]/api.php' into the family file, see https://www.mediawiki.org/wiki/Manual:Pywikibot/Use_on_third-party_wikis for more details.

pwb is able to any of the default mediawikis (like wikivoyage, wikipedia). Just not the custom added ones (mine).

pwb should be able to work with any MediaWiki wiki (and also with non-mediawiki wikis slightly modified). It works on Wikia, Vikidia, OSM and similar by default and some of my colleagues admin their personal MediaWIki installations using pwb successfully. But some parts of the code were not touched for years as the developer base is not much wide so maybe you found a hole. You can also try to ask on pwb's IRC and mailing list, where people with similar wiki instances sometimes chat about their problems and if you want, you can also acces me by email: dvorapa~seznam~cz ;)

Added the apipath variable but that didn't do anything. I also downloaded the latest core.tar.gz with the fixed generate-family.py, but the same issue persists with the pwb-api disconnect.

So I went ahead and tried to create a family file manually as per these directions. My wiki api is at wiki.[REDACTED].com/api.php

This is what it looks like:

from pywikibot import family

class Family(family.Family):
    name = 'finwiki'
    langs = {
        'en': 'wiki.[REDACTED].com',
        }
    def scriptpath(self, code):
        return {
            'en': '',
        }[code]

With this I get the same timeout error. Given the api is at /api.php and not /w/api.php, is the last scriptpath defined correctly? If I do 'en': '/' instead then I get this error: https://pastebin.com/wijHYxhd

Sc4s2cg updated the task description. (Show Details)

This is what it looks like:

LGTM.

I suggest you check what is in the response, the rawdata, using a print statement/function or something similar.

File "/home/peter/NetShare/core/pywikibot/data/api.py", line 1999, in submit
  result = json.loads(rawdata)

@zhuyifei1999 Request being made:

rawdata = http.request(
                    site=self.site, uri=uri,
                    method='POST',
                    body=body,headers=headers)

So rawdata is wiki.[REDACTED].com/api.php

Variables sent:

site:  finalwiki:en
uri:  /api.php
body:  action=query&meta=siteinfo%7Cuserinfo&siprop=namespaces%7Cnamespacealiases%7Cgeneral&continue=&uiprop=blockinfo%7Chasmsg&maxlag=5&format=json
headers:  {'Content-Type': 'application/x-www-form-urlencoded', 'user-agent': 'login (finalwiki:en; User:Petike) Pywikibot/3.1.dev0 (g1) requests/2.18.4 Python/3.6.3.final.0'}

I also printed out 'rawdata' from api.py by putting print(rawdata) before line 2005. It's requesting json but getting the Main_Page.html as response. The print output is here: https://pastebin.com/HYqRAiVt

Just a prompt to see if anyone has any idea?

So rawdata is wiki.[REDACTED].com/api.php

Theoretically that should be true, but did you check the uri? If that is indeed the case, does the uri actually lead to the mediawiki API if you visit it in browser?

Oh I see, uri: /api.php is printed. Is wiki.[REDACTED].com/api.php your mediawiki API endpoint if you visit in your browser? An API endpoint looks like https://www.mediawiki.org/w/api.php

As @zhuyifei1999 suggested, you should make sure the api uri is correct, if it leads where it should and set the proper uri to def apipath(self, code): return '/path to /api.php' into your family file (see e.g. https://phabricator.wikimedia.org/diffusion/PWBC/browse/master/pywikibot/families/wikia_family.py$28)

Also you could check the output what you get from API, what it looks like. Try to print what you actually get by Pywikibot and compare it to what you get with your script. That should help us find the issue inside Pywikibot's code if any. Maybe there is some encoding problem?

The variables recognized by Pywikibot you can modify in your family file:

Single code/lang wiki:
name = example
dbname = examplewiki
protocol = http/https (default https)
domain = www.example.com
scriptpath = '/w'
apipath = '/api.php'
langs[name] = www.example.com

Multiple codes/langs wiki:
langs[code] = en.example.com
codes = ['en', 'fr']
domain = example.com

The final structure:
protocol://langs[code]scriptpathapipath

If there is a bug on Pywikibot side, probably there is somewhere some of these variables hardcoded somewhere or incorrectly chosen a default or maybe generate_family_file is not correctly making scriptpath and apipath variables when you insert api path to it, so try to hardcode correct api path into the pywikbiot/data/api module directly and see what happens.

What is your whole api path please? Is it http://www.[REDACTED].com/api.php? I can try to set up my own wiki on wiki.dvorapa.cz with your api path and try to test if I could reproduce the issue and find a solution on Pywikibot's side.

@zhuyifei1999 yes, that is the endpoint. Going to wiki.[REDACTED].com/api.php gets me the same page as www.mediawiki.org/w/api.php

@Dvorapa the whole api path is http://wiki.[REDACTED].com/api.php

Just wanted to reply real quick before I implement you guys' suggestions.

@zhuyifei1999 yes, that is the endpoint. Going to wiki.[REDACTED].com/api.php gets me the same page as www.mediawiki.org/w/api.php

How about with some parameters? wiki.[REDACTED].com/api.php?action=query&format=json should look like https://www.mediawiki.org/w/api.php?action=query&format=json

@zhuyifei1999 yes, that is the endpoint. Going to wiki.[REDACTED].com/api.php gets me the same page as www.mediawiki.org/w/api.php

How about with some parameters? wiki.[REDACTED].com/api.php?action=query&format=json should look like https://www.mediawiki.org/w/api.php?action=query&format=json

Yup, I can confirm it's the same page.

I added this variable to the family file, but no change in error.

def apipath(self, code):
    return '/path to api.php'

Also you could check the output what you get from API, what it looks like. Try to print what you actually get by Pywikibot and compare it to what you get with your script. That should help us find the issue inside Pywikibot's code if any. Maybe there is some encoding problem?

Do you mean this output? It seems like pwb is requesting json but getting html instead.

Request being made:

rawdata = http.request(
                    site=self.site, uri=uri,
                    method='POST',
                    body=body,headers=headers)

So rawdata is wiki.[REDACTED].com/api.php

Variables sent:

site:  finalwiki:en
uri:  /api.php
body:  action=query&meta=siteinfo%7Cuserinfo&siprop=namespaces%7Cnamespacealiases%7Cgeneral&continue=&uiprop=blockinfo%7Chasmsg&maxlag=5&format=json
headers:  {'Content-Type': 'application/x-www-form-urlencoded', 'user-agent': 'login (finalwiki:en; User:Petike) Pywikibot/3.1.dev0 (g1) requests/2.18.4 Python/3.6.3.final.0'}

I also printed out 'rawdata' from api.py by putting print(rawdata) before line 2005. It's requesting json but getting the Main_Page.html as response. The print output is here: https://pastebin.com/HYqRAiVt

I went ahead and installed a brand new instance of mediawiki at wiki2.[REDACTED].com, with a new mysql database and everything. Getting the same Non-JSON response error as before.

Try:

$python -c "import requests; print(requests.post('https://en.wikipedia.org/w/api.php', 'action=query&meta=siteinfo|userinfo&siprop=namespaces|namespacealiases|general&continue=&uiprop=blockinfo|hasmsg&maxlag=5&format=json').json())"

(Replace https://en.wikipedia.org/w/api.php with your api path.)

See if it returns valid JSON data or raises an exception.

@Dalba It looks like I got a connection error: https://pastebin.com/smncxm0A

@Dvorapa were you able to replicate the issue?

@Sc4s2cg Not yet, sorry. BTW in LocalSettings.php, do you have the correct domain specified? (and not localhost?) @Urbanecm Do you have some MediaWiki installed to try this? I've only tried to install it on Toolforge, but with no success in database setup. (How could I create my own database "my_own_db" on Toolforge's tool?).

@Sc4s2cg I've also tried these three non-WMF wikis, all of them works as expected, so there must be something wrong in your config I think: https://testwiki.wiki, https://publictestwiki.com/wiki/Main_Page, https://www.thetestwiki.org/wiki/Main_Page

@Dvorapa Regarding database creation on toolforge, try this:

  1. Cat ~/replica.my.cnf and record your username stored in this file (it should begin with s for tools and with u for ordinary users)
  2. Run sql local
  3. Run CREATE DATABASE yourusernameanything (where anything is literally anything) to create a private database or yourusernameanything_p to create a public database
  4. Your DB server is at tools-db, credentials are in ~/replica.my.cnf

It should be possible to use PWB with non-WMF site, I used PWB for WMCZ's internal wiki, worked with no problems.

@Dvorapa yeah, I can confirm that LocalSettings has the domain specified and not localhost. I'm at a loss on what could be wrong. I'll try to do a fresh install of mediawiki on a different Ubuntu VM.

@Sc4s2cg I feel like sharing more details (like link to the wiki you're trying to use) to enable us to replicate the issue if we can is warranted. If you don't want to post it publishly, you can create a private paste via https://phabricator.wikimedia.org/paste/edit/form/36/, which will allow access to people you add via the "Subscribers" field (please include @Dvorapa and me, because we do not fulfil the second condition and we're trying to help you) and people who signed a NDA with the WMF.

To show complete working process, I can easily add my wiki to PWB.

urbanecm@notebook ~/bin/pywikibot-core                 
$ python3 generate_family_file.py                                                                                                                                                                           
                                                       
Usage: generate_family_file.py <url> <short name>                                                                                                                                                           
Example: generate_family_file.py https://www.mywiki.bogus/wiki/Main_Page mywiki                       
This will create the file families/mywiki_family.py                                                                                                                                                         
Please insert URL to wiki: https://titanium.webappky.cz/~urbanecm/testwiki/index.php/Hlavn%C3%AD_strana
Please insert a short name (eg: freeciv): urbanecmtestwiki                                                                                                                                                  
Generating family file from https://titanium.webappky.cz/~urbanecm/testwiki/index.php/Hlavn%C3%AD_strana
                                                                                                                                                                                                            
==================================                     
api url: https://titanium.webappky.cz/~urbanecm/testwiki/api.php                                      
MediaWiki version: 1.31.0-rc.0                         
==================================                                                                    
                                                        
Determining other languages...                                                                        
Loading wikis...                                       
  * cs... in cache                                                                                    
Writing /home/urbanecm/unsynced/git/wmf/gerrit/pywikibot/core/pywikibot/families/urbanecmtestwiki_family.py...
urbanecm@notebook ~/bin/pywikibot-core                                                                
$ vim user-config.py # Adding a username to user-config.py
urbanecm@notebook ~/bin/pywikibot-core             
$ python3 pwb.py login -family:urbanecmtestwiki -lang:cs
Password for user UrbanecmBot on urbanecmtestwiki:cs (no characters will be shown): 
Logging in to urbanecmtestwiki:cs as UrbanecmBot
WARNING: API warning (main): Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce> for notice of API deprecations and breaking changes.
WARNING: API warning (login): Main-account login via "action=login" is deprecated and may stop working without warning. To continue login with "action=login", see [[Special:BotPasswords]]. To safely continue using main-account login, see "action=clientlogin".
WARNING: /home/urbanecm/unsynced/git/wmf/gerrit/pywikibot/core/pywikibot/tools/__init__.py:1719: UserWarning: File /home/urbanecm/unsynced/git/wmf/gerrit/pywikibot/core/pywikibot.lwp had 644 mode; converted to 600 mode.
  warn(warn_str.format(filename, st_mode - stat.S_IFREG, mode))

Logged in on urbanecmtestwiki:cs as UrbanecmBot.
urbanecm@notebook ~/bin/pywikibot-core 
$ # Some warnings throwned above, but non-critical, so we're logged in
urbanecm@notebook ~/bin/pywikibot-core 
$ python3 pwb.py add_text -page:"Test page for T196683" -text:"Some text for T196683" -family:urbanecmtestwiki -lang:cs
Loading Test page for T196683...


>>> Test page for T196683 <<<
@@ -1 +1,2 @@
- I created a page
+ I created a page
+ Some text for T196683

Do you want to accept these changes? ([y]es, [N]o, [a]ll, open in [b]rowser,
[q]uit): y
Sleeping for 8.1 seconds, 2018-06-23 16:12:07
Page [[Test page for T196683]] saved
urbanecm@notebook ~/bin/pywikibot-core 
$ python3
Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pywikibot
>>> site = pywikibot.Site('cs', 'urbanecmtestwiki')
>>> page = pywikibot.Page(site, u"Test page for T196683")
>>> print(page.text)
I created a page
Some text for T196683
>>> Ctrl+D
<class 'NameError'>
CRITICAL: Closing network session.
urbanecm@notebook ~/bin/pywikibot-core 
$

You can verify sucessfullness of such adding on https://titanium.webappky.cz/~urbanecm/testwiki/index.php?title=Test_page_for_T196683&diff=3&oldid=2.

For the record, see below for version details.

urbanecm@notebook ~/bin/pywikibot-core 
$ python3 pwb.py version
Pywikibot: [ssh] pywikibot-core.git (46de1bc, g9726, 2018/06/21, 08:27:56, ok)
Release version: 3.1.dev0
requests version: 2.18.1
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0]
PYWIKIBOT2_DIR: Not set
PYWIKIBOT2_DIR_PWB: 
PYWIKIBOT2_NO_USER_CONFIG: Not set
Config base dir: /home/urbanecm/unsynced/git/wmf/gerrit/pywikibot/core
Usernames for family "commons":
        *: UrbanecmBot (no sysop configured)
Usernames for family "wikipedia":
        *: UrbanecmBot (no sysop configured)
Usernames for family "wikiversity":
        *: UrbanecmBot (no sysop configured)
Usernames for family "urbanecmtestwiki":
        *: UrbanecmBot (no sysop configured)
Usernames for family "wikidata":
        wikidata: UrbanecmBot (no sysop configured)
urbanecm@notebook ~/bin/pywikibot-core 
$

You are free to test with this wiki, registration should be open.

For the record, I'm posting titanium's OS version details.

urbanecm@titanium ~ 
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="16.04.4 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.4 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
urbanecm@titanium ~ 
$

That form is only available to ndas, ops, and Trusted-Contributors. Shall we add them to the last one?

Good point, didn't know that. I won't oppose adding them to Trusted Contributors, if you think it's okay for this purpose. <offtopic>Why only creating private pastes is restricted, if anything, then making existing public pastes private should be restritcted instead</offtopic>

Well, I installed mediawiki in a fresh Ubuntu 18.04 installation. Restored the database, then used pwb and everything worked perfectly.

If anyone is still interested I can make a private topic if you'd like to mess around in the old wiki? @Urbanecm @zhuyifei1999

I've added you to Trusted Contributors. Now, you can see https://phabricator.wikimedia.org/paste/edit/form/36/ and should be able to fill details you don't want to share publicly in there. Please add me to subscribers, otherwise I won't be able to access the paste as well :D.

Vvjjkkii renamed this task from pwb.py cannot login to self-hosted mediawiki site to wfbaaaaaaa.Jul 1 2018, 1:06 AM
Vvjjkkii triaged this task as High priority.
Vvjjkkii updated the task description. (Show Details)
Vvjjkkii removed a subscriber: Aklapper.
JJMC89 renamed this task from wfbaaaaaaa to pwb.py cannot login to self-hosted mediawiki site.Jul 1 2018, 1:59 AM
JJMC89 raised the priority of this task from High to Needs Triage.
JJMC89 updated the task description. (Show Details)
JJMC89 added a subscriber: Aklapper.

Well, I installed mediawiki in a fresh Ubuntu 18.04 installation. Restored the database, then used pwb and everything worked perfectly.

If anyone is still interested I can make a private topic if you'd like to mess around in the old wiki? @Urbanecm @zhuyifei1999

I would close this and if anyone in the future will get stuck in similar problems, we can always reopen this

xSavitar assigned this task to Dvorapa.
Dvorapa changed the task status from Resolved to Invalid.Oct 1 2018, 12:50 PM
Dvorapa removed Dvorapa as the assignee of this task.