Jump to content

Manual talk:Pywikibot/2020

Add topic
From mediawiki.org


Please use one of the communication channels listed on Manual:Pywikibot/Communication rather than using this discussion board. There is very little traffic here, so it may take a while before you get a response.

How to upload images to commons via command line?

[edit]

I am trying to do this for ages, but there is a lot of old information and misdirections.


I just want to upload a file via command line. Can someone here point me to a clear reference resource where I can really learn how to do it?

sorry about the angry tone, lots of ours of failure. TiagoLubiana (talk) 20:17, 19 April 2020 (UTC)Reply

Hi, download and install Pywikibot according to Manual:Pywikibot/Installation and then run python pwb.py upload [parameters]. See https://doc.wikimedia.org/pywikibot/master/scripts/scripts.html?highlight=upload#module-scripts.upload for more details about the parameters. Also feel free to ask about anything unclear. Dvorapa (talk) 22:52, 19 April 2020 (UTC)Reply
When you click the link , it shows "Not available" Akbarali (talk) 10:52, 21 February 2023 (UTC)Reply
Current link: https://doc.wikimedia.org/pywikibot/stable/scripts_ref/scripts.html#module-scripts.upload Dvorapa (talk) 16:42, 26 February 2023 (UTC)Reply
In the end it all worked by:
Installing pywikibot via pip
Adding user-config.py file to the same folder as upload.py (and the directory of the files to upload too)
Running the uploads script
I was not able to specify some things, though, like wikidata items depicted, or choose the proper license, or adding a legend. Any tips on that?
Thanks! TiagoLubiana (talk) 23:37, 19 April 2020 (UTC)Reply
Can anyone prepare the video tutorial of uploading photos using command line (python) into Wikimedia Commons Akbarali (talk) 10:54, 21 February 2023 (UTC)Reply
Just read the docs, there's everything Dvorapa (talk) 16:42, 26 February 2023 (UTC)Reply
Not everything is supported by Pywikibot currently, see T223820. You can update upload.py script or write your own script using this brief manual, this basic template and this api module if you need specific feature not yet supported by Pywikibot. You could also propose a patch to Pywikibot if you manage to fix any of these. Dvorapa (talk) 23:51, 19 April 2020 (UTC)Reply
There is a parameter that allows for adding a file description string; this will become the wiki code of the Commons page of the file that you uploaded. By the way, the best description of parameters is to be found in upload.py itself, in my opinion. It's more clear than the documentations online.
python3 pwb.py upload "path/to/some_file.png" -summary:"uploaded with pywikibot" "source code string of the file page" -ignorewarn -always -keep
So in the source code string, you can include everything that you usually find on a Commons page (in wiki syntax), like filedesc with the information template, the license-header with the license template of your choice and categories.
--Hbf878 (talk) 14:56, 21 April 2020 (UTC)Reply
Okay, thank you for the answers!
I will take a look and try to figure a way of doing it. TiagoLubiana (talk) 20:35, 21 April 2020 (UTC)Reply

internal_api_error_Error_when_running_a_script

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Hello, I have installed the latest pywikibot on a centos7 server (python3/pip3) and configured it to successfully log in to a bot account I have created on my private MW 34.x wiki (yay!), but when I try to run a basic script such as "add_text.py" I get an vague error message relating to the API. It's not a permissions error, I've solved that. Now it says, "ERROR: Detected MediaWiki API exception internal_api_error_Error". Can anyone please help me debug this? Here's the error:

[revansx@meza1 core_stable]$ python3 pwb.py login
Logged in on somewiki:en as MrBot.
[revansx@meza1 core_stable]$ python3 pwb.py add_text -cat:Some_Pages -text:'Hello World'
WARNING: API error internal_api_error_Error: [XqtN7LIvu8DlHjdVfQAmeQAAAAg] Caught exception of type Error
ERROR: Detected MediaWiki API exception internal_api_error_Error: [XqtN7LIvu8DlHjdVfQAmeQAAAAg] Caught exception of type Error
[errorclass: Error]; raising
Traceback (most recent call last):
  File "pwb.py", line 390, in <module>
    if not main():
  File "pwb.py", line 385, in main
    file_package)
  File "pwb.py", line 101, in run_python_file
    main_mod.__dict__)
  File "./scripts/add_text.py", line 360, in <module>
    main()
  File "./scripts/add_text.py", line 352, in main
    for page in generator:
  File "/home/revansx/core_stable/pywikibot/pagegenerators.py", line 1554, in CategorizedPageGenerator
    for a in category.articles(**kwargs):
  File "/home/revansx/core_stable/pywikibot/page/__init__.py", line 2983, in articles
    member_type=['page', 'file']
  File "/home/revansx/core_stable/pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "/home/revansx/core_stable/pywikibot/site/__init__.py", line 4052, in categorymembers
    total=total, g_content=content, **cmargs)
  File "/home/revansx/core_stable/pywikibot/tools/__init__.py", line 1790, in wrapper
    return obj(*__args, **__kw)
  File "/home/revansx/core_stable/pywikibot/site/__init__.py", line 1943, in _generator
    gen = gen_class(type_arg, **req_args)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2921, in __init__
    QueryGenerator.__init__(self, **kwargs)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2456, in __init__
    self.site._paraminfo.fetch('query+' + mod for mod in self.modules)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 395, in fetch
    self._init()
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 274, in _init
    self._fetch(self.preloaded_modules)
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 478, in _fetch
    result = request.submit()
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2251, in submit
    self._data = super(CachedRequest, self).submit()
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 2040, in submit
    if self._internal_api_error(code, error, result):
  File "/home/revansx/core_stable/pywikibot/data/api.py", line 1910, in _internal_api_error
    raise e
pywikibot.data.api.APIMWException: internal_api_error_Error: [XqtN7LIvu8DlHjdVfQAmeQAAAAg] Caught exception of type Error
[errorclass: Error]
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.data.api.APIMWException'>
Revansx (talk) 04:43, 1 May 2020 (UTC)Reply
Hello Revansx, this is definitely an internal Mediawiki error (yes, it looks like you found a bug in mediawiki :), not in pywikibot itself)
You're logging at somewiki, you can ask admin of this wiki to update its mediawiki version to try to get the bug removed. If you're sure it's using up-to-date version, please put full console log of your command (if you've stripped in above paste) and the output of python3 pwb.py version. Framawiki (talk) 13:59, 1 May 2020 (UTC)Reply
I'm the admin of the wiki as well. The wiki is 1.34.1. I'm running:
  • Python 3.5.6
  • pip 20.1 from /usr/lib/python3.5/site-packages/pip (python 3.5)
And my python3 pwb.pr version response is:
$ python3 pwb.py version
Pywikibot: [https] r-pywikibot-core.git (2cf6739, g1, 2020/04/05, 16:57:37, OUTDATED)
Release version: 3.1.dev0
requests version: 2.23.0
  cacerts: /usr/lib/python3.5/site-packages/certifi/cacert.pem
    certificate test: ok
Python: 3.5.6 (default, Nov 16 2018, 15:50:58)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-28)]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB:
PYWIKIBOT_NO_USER_CONFIG: Not set
Config base dir: /home/revansx/core_stable
Usernames for family "somewiki":
        en: MrBot
Do you see anything specific I should update? Revansx (talk) 15:48, 1 May 2020 (UTC)Reply
As you were told, this is beyond Pywikibot, it's an internal error of the wiki (despite the bot is triggering it). You may ask at Project:Support desk but you will need to provide the traceback of the exception thrown by the server engine. Matěj Suchánek (talk) 08:02, 2 May 2020 (UTC)Reply
Perhaps you might try to reinstall MediaWiki as your first installation might be broken. Dvorapa (talk) 08:13, 2 May 2020 (UTC)Reply
I appreciate the responses. I'll do what has been recommended and reply back here with whatever the solution turned out to be. Thanks. Revansx (talk) 13:10, 2 May 2020 (UTC)Reply
problem solved. There was an permissions issue incurred by an experimental extension I have installed. I disabled the extension and my pwb worked as expected. Thanks everyone Revansx (talk) 18:45, 2 May 2020 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

BOT watchlist notification that triggers a PWB script

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


The PWB bot user account on my wiki has a watchlist and receives notifications like any other user. Has anyone every written a pwb script that reads its un-read notifications and calls other scripts with properties based what pages are referred to in the un-read notifications? Revansx (talk) 19:48, 2 May 2020 (UTC)Reply

There is a script watchlist.py in scripts/archive folder which can be used for this issue. Please not that this script is archived not currently maintained by developers. Please follow the steps in archive/readme.rst how to use it. You may open a phab task to recover it to the main repository and activate further development at any time.  @xqt 14:41, 1 April 2021 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

login key error

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Hi. Pywikibot had been working fine. Then it started flagging errors, maybe from a python update. i updated pywikibot and python no longer flags errors. But I don't know why I can't log in. i set pywikibot all over again. any ideas? mediawiki 1.33 python 3.8.3


Traceback (most recent call last):

  File "pwb.py", line 360, in <module>

   if not main():

  File "pwb.py", line 352, in main

   run_python_file(filename,

  File "pwb.py", line 73, in run_python_file

   exec(compile(source, filename, 'exec', dont_inherit=True),

  File "./scripts/login.py", line 185, in <module>

   main()

  File "./scripts/login.py", line 167, in main

   site.login(autocreate=autocreate)

  File "/home/yutkeej/pywikibot/pywikibot/tools/__init__.py", line 1499, in wrapper

   return obj(*__args, **__kw)

  File "/home/yutkeej/pywikibot/pywikibot/site/__init__.py", line 1931, in login

   if login_manager.login(retry=True, autocreate=autocreate):

  File "/home/yutkeej/pywikibot/pywikibot/login.py", line 301, in login

   cookiedata = self.getCookie()

  File "/home/yutkeej/pywikibot/pywikibot/tools/__init__.py", line 1584, in wrapper

   return obj(*new_args, **new_kwargs)

  File "/home/yutkeej/pywikibot/pywikibot/data/api.py", line 3197, in getCookie

   and (response['messagecode'] == 'login-throttled'

KeyError: 'messagecode'

CRITICAL: Exiting due to uncaught exception <class 'KeyError'> 2806:106E:1E:1870:9124:3F37:C7C3:A07E (talk) 03:54, 7 August 2020 (UTC)Reply

Hi, this is an issue with CAPTCHA. Your bot account is not yet trusted by wiki administrators. You can either ask your wiki admins to assign your bot account a Bot flag, or a Confirmed account flag. The Confirmed account flag is assigned automatically when your account is 4 days old or makes more than 10 edits (en:Wikipedia:User_access_levels#Autoconfirmed_users). Dvorapa (talk) 12:48, 8 August 2020 (UTC)Reply
@Xqt Perhaps we should catch this new account captcha (and solve it) somehow too. Or we could just throw a better error message than login-throttled (which has nothing to do with captcha) Dvorapa (talk) 12:50, 8 August 2020 (UTC)Reply
phab:T261061  @xqt 08:58, 23 August 2020 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

ndash

[edit]

How can a ndash be inserted, e.g. using replace.py? Leyo 21:21, 10 August 2020 (UTC)Reply

Where do you want to insert it? Dvorapa (talk) 08:02, 12 August 2020 (UTC)Reply
A right-click and "Paste" on terminal usually works. Or use user-fixes.py and either paste it using a text editor or type "\u2013" where you want it. In Python 3.8, you should be able to use \N{EN DASH} as well but I couldn't test this. Matěj Suchánek (talk) 16:02, 13 August 2020 (UTC)Reply
Thanks for the replies. I would like to use the terminal to run replace.py and to define the replacements. I had tried to paste the ndash before, but it turned out to be converted into a hyphen minus. I had also tried \u2013, but it would have been inserted as text, not as ndash. Leyo 20:54, 18 August 2020 (UTC)Reply

generate_user_files error

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


Hi there, I desperately need this tool to help groom 1500 imported SharePoint wiki pages in a private wiki. My setup is:

azureuser@aeran-linux-vm-002:~/pywikibot/core$ python pwb.py version
WARNING: Http response status 404
Pywikibot: pywikibot/__init__.py (, -1 (unknown), 2020/08/29, 01:01:30, n/a)
Release version: 4.2.0
requests version: 2.21.0
 cacerts: /etc/ssl/certs/ca-certificates.crt
   certificate test: ok
Python: 3.7.3 (default, Jul 25 2020, 13:03:44)
[GCC 8.3.0]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB:
PYWIKIBOT_NO_USER_CONFIG: 2
Config base dir: /home/azureuser/pywikibot/core

When I attempt to initialise pywikibot I get:

azureuser@aeran-linux-vm-002:~/pywikibot/core$ python pwb.py generate_user_files.py
Traceback (most recent call last):File "pwb.py", line 360, in <module>
    if not main():
  File "pwb.py", line 355, in main
    file_package)
  File "pwb.py", line 74, in run_python_file
    main_mod.__dict__)
  File "./generate_user_files.py", line 473, in <module>
    main()
  File "./generate_user_files.py", line 443, in main
    local_args = pywikibot.handle_args(args)
  File "/home/azureuser/pywikibot/core/pywikibot/bot.py", line 878, in handle_args
    pywikibot.Site()
  File "/home/azureuser/pywikibot/core/pywikibot/tools/__init__.py", line 1434, in wrapper
    return obj(*__args, **__kw)
  File "/home/azureuser/pywikibot/core/pywikibot/__init__.py", line 1249, in Site
    _sites[key] = interface(code=code, fam=fam, user=user)
  File "/home/azureuser/pywikibot/core/pywikibot/tools/__init__.py", line 1517, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/home/azureuser/pywikibot/core/pywikibot/site/__init__.py", line 1705, in __init__
    BaseSite.__init__(self, code, fam, user)
  File "/home/azureuser/pywikibot/core/pywikibot/tools/__init__.py", line 1517, in wrapper
    return obj(*new_args, **new_kwargs)
  File "/home/azureuser/pywikibot/core/pywikibot/site/__init__.py", line 720, in __init__
    if code.lower() != code:
AttributeError: 'NoneType' object has no attribute 'lower'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>

Obviously something pretty fundamental with my install, but I'm at a loss. Andrew Campbell 67 (talk) 22:20, 29 August 2020 (UTC)Reply

No reply here or on #pywikibot, but I see that this is a bug (discovered after I posted) https://phabricator.wikimedia.org/T261771
There is a fix in testing. Andrew Campbell 67 (talk) 05:45, 2 September 2020 (UTC)Reply
I have the same issues, I tried to debug code with no good result.
In file __init__.py in pywikibot/ at line 117 the code variable is set in None in
def Site(code=None, fam=None, user=None, sysop=None, interface=None, url=None):
but it's not manage None as value for code variable
I hope it will be solved quickly. :) 165.225.86.65 (talk) 12:21, 2 September 2020 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

SSL Certificate Verification error

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


I am currently trying to add the website https://schoolwiki.in/ into Pywikibot, so as to make use of the bot in Schoolwiki. While trying to run the code "pytho pwb.py generate_family_file" according to the instructions mentioned here, I am getting the error:
pywikibot.exceptions.FatalServerError: HTTPSConnectionPool(host='schoolwiki.in', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')))
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.FatalServerError'>
Is there any method to resolve this issue? Adithyak1997 (talk) 19:55, 10 October 2020 (UTC)Reply
Made a phab task with phab:T265210  @xqt 12:20, 11 October 2020 (UTC)Reply
Did you try to enter schoolwiki.in manually into your user-config.py ? This is just a text file, add a line like
usernames=['schoolwiki.in']='edoderoobot' Edoderoo (talk) 09:31, 11 October 2020 (UTC)Reply
This is about the familiy file not the user-config  @xqt 11:03, 11 October 2020 (UTC)Reply
I tried to generate the family-file for edoderoobot, and got the same error. It might be an issue on the schoolwiki.in setup. Edoderoo (talk) 11:14, 11 October 2020 (UTC)Reply
Did you try any method to bypass the certification related error? I mean something like the ones mentioned here? Adithyak1997 (talk) 11:37, 11 October 2020 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

NoUsername error

[edit]

The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.


While trying to login to Pywikibot using the command python3 pwb.py login, I am getting the following error


Skipped '/home/user/pywikibot/core_stable/user-config.py': writeable by others.

family and mylang are not set.

Defaulting to family='wikipedia' and mylang='test'.

WARNING: No user is logged in on site wikipedia:test

Traceback (most recent call last):

  File "/home/user/pywikibot/core_stable/pywikibot/login.py", line 115, in __init__

   user = code_to_usr.get(site.code) or code_to_usr['*']

KeyError: '*'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "pwb.py", line 363, in <module>

   if not main():

  File "pwb.py", line 355, in main

   run_python_file(filename,

  File "pwb.py", line 74, in run_python_file

   exec(compile(source, filename, 'exec', dont_inherit=True),

  File "./scripts/login.py", line 192, in <module>

   main()

  File "./scripts/login.py", line 174, in main

   site.login(autocreate=autocreate)

  File "/home/user/pywikibot/core_stable/pywikibot/tools/__init__.py", line 1481, in wrapper

   return obj(*__args, **__kw)

  File "/home/user/pywikibot/core_stable/pywikibot/site/__init__.py", line 333, in login

   login_manager = api.LoginManager(site=self, user=self.username())

  File "/home/user/pywikibot/core_stable/pywikibot/tools/__init__.py", line 1481, in wrapper

   return obj(*__args, **__kw)

  File "/home/user/pywikibot/core_stable/pywikibot/login.py", line 117, in __init__

   raise NoUsername(

pywikibot.exceptions.NoUsername: ERROR: username for wikipedia:test is undefined.

If you have a username for that site, please add a line to user-config.py as follows:

usernames['wikipedia']['test'] = 'myUsername'

CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.NoUsername'>


Since the wiki is a third party wiki, I have actually created password.py file, added the family file and also created the user-config.py file. But still the error is showing Adithyak1997 (talk) 05:14, 30 December 2020 (UTC)Reply

I copied this to https://phabricator.wikimedia.org/T270939.  @xqt 09:09, 30 December 2020 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Use upload script with wildcards

[edit]

Couldn't find it anywhere in documentation, but is it possible to use upload script with wildcards?

If I use

upload /path/to/files/foo*

the scripts suggest all the full paths of foo* files as a description. Something like

/path/to/files/foo 1 /path/to/files/foo 2 /path/to/files/foo 3

which is, of course, is not what I want. It's the same with the -summary key.

In case of

upload /path/to/files/foo* -descfile:description.txt

I get an error "Both a description and a -descfile were provided. Please specify only one of those."

The workaround is to separately put all the foo* files to a separate folder and use -recursive.

upload -recursive /path/with/files -descfile:description.txt

works fine, but you have to go through the hassle of copying files to a seperate folder. RedKhan16 (talk) 20:07, 30 December 2020 (UTC)Reply