Manual talk:Pywikibot

Jump to navigation Jump to search

About this board


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.

Miles Fides (talkcontribs)

I rather have some questions than a problem.

  • Does anyone know how the pywikibot would handle a timeout?
  • Has anybody ever experienced a timeout with the pywikibot?
  • What is the default ttl and the default reaction to a timeout?


Zbmath authorid (talkcontribs)

I would be interested in the answer to these questions...

Reply to "Timeout handling"

How to disable "Sleeping for N seconds" on PyWikiBot

Summary by Dvorapa

Sleeping for N seconds should not be disabled as it makes load to servers (talkcontribs)

How to disable "Sleeping for N seconds" on PyWikiBot

Xqt (talkcontribs)

You shouldn't. This is necessary to throttle writing to the site high frequently and it is restricted on most wiki's.

Framawiki (talkcontribs)

Why you want to disable a security ? Not a good idea I think :)

Sergezolotukhin (talkcontribs)
Xqt (talkcontribs)

maxthrottle isn't the right parameter for that.

Deleting blank lines with inside templates

Theklan (talkcontribs)

Hello! I have been using to delete obsolete lines inside templates, but now I have some empty lines. I can't find a way to delete them... can someone help with this? Thanks!

Matěj Suchánek (talkcontribs)

Please share more information: What is your regex, what does your input look like, what do you expect?

Theklan (talkcontribs)
Matěj Suchánek (talkcontribs)

Don't you want to replace it with a single newline \n? The problem I can see is that there were some spaces between the newlines, which you can fix with \n *\n *\n.

Theklan (talkcontribs)

Thanks for the clue! Is there any other script to delete blank lines only inside templates?

Matěj Suchánek (talkcontribs)

None that I know.

Reply to "Deleting blank lines with inside templates"
Summary by Dvorapa

Everybody can use pywikibot, but please be careful to local community restrictions

SamiIslam (talkcontribs)


Can a normal user use the pywikibot functionality from a wiki site to create a site from a text file? Or is that something only an admin would have to do on the server hosting the wiki?



Xqt (talkcontribs)

There is a script "" to do this but it is may be local community restrictions to allow or discard edits in this way.

Summary by Dvorapa

The combination of and can effectively move pages and update redirects. There is currently no script, which could do both actions at once

Jc86035 (talkcontribs)

Does update redirects as well to avoid creating double redirects?

This post was hidden by Jc86035 (history)
Xqt (talkcontribs)

Currently not.

Jc86035 (talkcontribs)

Are there any scripts which do so?

XXN (talkcontribs)

Pagegenerator in different language.

Summary by Dvorapa

Pagegenerator for the Czech Wikipedia is -family:wikipedia -lang:cs

Walter Klosse (talkcontribs)

How i make pagegenerator for category on wikipedia in czech language?

Framawiki (talkcontribs)

Hello, do you want something like

python replace "1" "2" -lang:cz -category:test


Dvorapa (talkcontribs)

correct is -lang:cs

Replacing template with text

Summary by Dvorapa

To work with templates there is a script. It can easily get e.g. category of templates to process by -cat parameter (talkcontribs)


I need a script that:

1) Select pages that are in a specific category

2) Delete in those pages an old template with its parameters (that could also be sub-templates); the template is the same, but the content is different for all, so I can't specify manually the text

3) And replace it with a text (a new template with standard content for all)

It's possible? I see something in '''' (point 1 and 3), but I'm not sure it can do the 2nd; and it seems that '''' can only replace the template name.


Xqt (talkcontribs)

Try script.

Glz19 (talkcontribs)

Thank you for the answer. It's possible with it selecting a category, for work only on pages in it? I read the documentation page but I can't see it.

Xqt (talkcontribs)

All scripts have a documentation with it. Just use -help option. In your case -cat:<categoryname> should do it. (talkcontribs)


I'm new to pywikibot and am stuck on getting a login failed (aborted) message.

When I try to use with the argument "double" and am prompted for what action to take, whenever I choose to "accept changes" I get that the Login failed(aborted) even when I manually input the bot password.

The login works for other scripts such as pagefromfile or just simply using the script.

Thanks for the help

Framawiki (talkcontribs) (talkcontribs)

Thanks for the help,

here is the shell history after I ran the command.

The wikibot is initially able to login, but after it wants to make the first change it prompts the user for the password (The login will fail even with the right password).

Reply to " Login Failed (Aborted)"

removing references from wikidata doesn't work

Summary by Soued031

false alarm

Soued031 (talkcontribs)

Hello, I found a bug in pywikibot but I am not sure if I use the method correctly. Deleting a reference does not seem to work. I'm using the last version from git. If you want I have a fix, but since I cannot find any documentation about pywikibot or an explanation of how a method should be written the fix seems out of place. Link with diff and the code that I'm right now using to modify wikidata:

Matěj Suchánek (talkcontribs)

The docstring of Claim.removeSources says: @type sources: list of pywikibot.Claim, which['P1082'][i].sources is not. That is a list of key: list of pywikibot.Claim mappings.

Soued031 (talkcontribs)

Thanks for you answer! So how does the code need to be changed as I haven't seen any example of removeSource(s)?I mean I understand that the type is wrong but how do I achieve the "right" type?

Matěj Suchánek (talkcontribs)

I hope this will work (it should remove all references attached to a statement):

sources = []
for source in claim.sources:
    for value in source.values():
Soued031 (talkcontribs)

Thanks a lot your code snippet works!

Soued031 (talkcontribs)


I've written a script whose goal is to write the population for (only at the moment) per year, which can be found here: When running the script I actually get 3 Warnings;

WARNING: /home/edson/Bureau/core/pywikibot/ _NotImplementedWarning: claim without on_item set is deprecated.

  return fn(self, *args, **kwargs)

WARNING: /home/edson/Bureau/core/pywikibot/ UserWarning: Neither claim.on_item nor baserevid provided

  return fn(self, *args, **kwargs)

WARNING: API error noclaim: The "claim" parameter must be set.

Traceback (most recent call last):

  File "", line 263, in <module>

   if not main():

  File "", line 256, in main

   run_python_file(filename, [filename] + args, argvu, file_package)

  File "", line 120, in run_python_file


  File "./", line 38, in <module>


  File "/home/edson/Bureau/core/pywikibot/", line 5002, in addQualifier

   data = self.repo.editQualifier(self, qualifier, **kwargs)

  File "/home/edson/Bureau/core/pywikibot/", line 1331, in callee

   return fn(self, *args, **kwargs)

  File "/home/edson/Bureau/core/pywikibot/", line 7813, in editQualifier

   data = req.submit()

  File "/home/edson/Bureau/core/pywikibot/data/", line 2195, in submit

   raise APIError(**result['error']) noclaim: The "claim" parameter must be set. [help:See for API usage. Subscribe to the mediawiki-api-announce mailing list at &lt;; for notice of API deprecations and breaking changes.]

<class ''>

CRITICAL: Closing network session.

What am I doing wrong?

Dvorapa (talkcontribs)
Matěj Suchánek (talkcontribs)

How does your code look like?

Soued031 (talkcontribs)
Matěj Suchánek (talkcontribs)

Oops, I see now.

The solution is to move the bottom line (item.addClaim) just before # add qualifier to claim.

Soued031 (talkcontribs)

@Matěj Suchánek Great it works! Thanks for the fast answer. Do I need to do something special to ask for bot rights?

Matěj Suchánek (talkcontribs)

If you want to run a bot on Wikidata, I strongly recommend you requesting the flag at d:WD:RFBOT.

Soued031 (talkcontribs)

Thanks I will look at it.