Topic on Manual talk:Pywikibot

[SOLVED] incorrect api.php path in command line

3
3dmahdi (talkcontribs)

MW 1.19.3

When I want to login with bot to my wiki I see this error:

No handlers could be found for logger "pywiki"
Logging in to westeros:fa as SiteBot via API.
Traceback (most recent call last):
  File "C:\pywikipedia\login.py", line 436, in <module>
    main()
  File "C:\pywikipedia\login.py", line 432, in main
    loginMan.login()
  File "C:\pywikipedia\login.py", line 319, in login
    cookiedata = self.getCookie(api)
  File "C:\pywikipedia\login.py", line 181, in getCookie
    response, data = query.GetData(predata, self.site, sysop=self.sysop, back_response = True)
  File "C:\pywikipedia\pywikibot\support.py", line 121, in wrapper
    return method(*__args, **__kw)
  File "C:\pywikipedia\query.py", line 143, in GetData
    res, jsontext = site.postForm(path, params, sysop, site.cookies(sysop = sysop) )
  File "C:\pywikipedia\wikipedia.py", line 6460, in postForm
    cookies=cookies)
  File "C:\pywikipedia\wikipedia.py", line 6514, in postData
    raise PageNotFound(u'Page %s could not be retrieved. Check your family file ?' % url)
pywikibot.exceptions.PageNotFound: Page http://www.westeros.ir/w/api.php could not be retrieved. Check your family file?

My family file is this:

# -*- coding: utf-8  -*-

import family

# westeros

class Family(family.Family):
    def __init__(self):
        family.Family.__init__(self)

        self.name = 'westeros'

        self.langs = {
                'fa': 'www.westeros.ir',
        }
        
    def version(self, code):
        return "1.19.3"
	def scriptpath(self, code):
		return '/wiki'
	def apipath(self, code):
		return '/wiki'

api.php is in '/wiki' folder and defined correctly in family file, I don't know why it says "Page http://www.westeros.ir/w/api.php could not be retrieved"? Where should I change "/w" to "/wiki" other than family.py file?

Legoktm (talkcontribs)

Hi. The issue is in your indentation. Try:

# -*- coding: utf-8  -*-

import family

# westeros

class Family(family.Family):
    def __init__(self):
        family.Family.__init__(self)

        self.name = 'westeros'

        self.langs = {
                'fa': 'www.westeros.ir',
        }
        
    def version(self, code):
        return "1.19.3"
    def scriptpath(self, code):
        return '/wiki'
    def apipath(self, code):
        return '/wiki'

Rather than tabs, you should use 4 spaces, which will keep everything consistent over multiple computers/operating systems.

3dmahdi (talkcontribs)

Thank you very much! That was the problem. Now my bot can login and edit pages! :)

Reply to "[SOLVED] incorrect api.php path in command line"