Manual talk:Pywikibot/2017


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.

Replace the whole text

edit

Is there any script i can use to replace the whole wiki text of a page? I only found replace.py which replaces a list of words or add_text.py which can add texts to the existing one. Has somebody a hint for me? Aschroet (talk) 06:55, 9 May 2017 (UTC)Reply

replace.py could do it:
pwb.py replace -regex ".*" "Any text you want to have on this page" -page:user:Aschroet/sandbox  @xqt 07:16, 9 May 2017 (UTC)Reply
Better use:
pwb.py replace -regex "(?s).+" "Any text you want to have on this page" -page:user:Aschroet/sandbox  @xqt 07:28, 9 May 2017 (UTC)Reply
Thank you. A batch replacement is not possible, or? Aschroet (talk) 08:57, 9 May 2017 (UTC)Reply
For small text you may use -pairsfile. Another ideas is using fixes. You have to modify your user-fixes.py for replacement.
I think the best script would be using pagefromfile.py; refer -help for mor Information about that.  @xqt 10:30, 9 May 2017 (UTC)Reply

No module named pywikibot

edit
CMD writing no module named pywikibot when i start login.py KlosseBot (talk) 19:02, 2 July 2017 (UTC)Reply
Looks like your cmd has opened the "../core/scripts" path. You should start from parent "core" path and use the pwb.py wrapper script:
pwb.py login  @xqt 06:01, 7 September 2017 (UTC)Reply
And when i write python pwb.py login it said no module named request. 2A00:1028:9192:FA72:F903:A911:3814:C073 (talk) 19:30, 2 July 2017 (UTC)Reply
You have to install request module as a side package first. Read the message and do as proposed. The message is:
Python module 'requests' is required.
Try running 'pip install requests'
do it with the command
pip install requests  @xqt 04:30, 3 July 2017 (UTC)Reply
I executed "pip install requests", it did so, but the same error doesn't go away. I tried both Python 3.6 and 2.7, it's the same with both. 188.23.125.244 (talk) 00:16, 6 September 2017 (UTC)Reply
Hello, can you type python pwb.py version and post here what you obtain ? Framawiki (talk) 20:30, 2 July 2017 (UTC)Reply
This doesn't even work for me, as it gets an error in line 163 of pwb.py 188.23.125.244 (talk) 00:17, 6 September 2017 (UTC)Reply
Did you installed requests for both python releases?  @xqt 05:49, 6 September 2017 (UTC)Reply
I installed 2.7 after trying 3.6. I eventually got things to work after installing pip seperately again and then installing requests via "pip install requests" and restarting. I may have repeated this some times and can't pinpoint what got things to work, but i eventually got it to work. 88.117.63.15 (talk) 22:58, 6 September 2017 (UTC)Reply
'pip install requests' doesnt work KlosseBot (talk) 07:41, 11 July 2017 (UTC)Reply
What is your python version? I propose using 2.7.9 or higher or 3.4 or higher release because the en:python package installer (pip) is shipped with these versions. Otherwise you have to install pip first.  @xqt 08:52, 11 July 2017 (UTC)Reply
I have 3.4 but still it isnt pip in it. How do i install it? KlosseBot (talk) 19:31, 15 July 2017 (UTC)Reply
Maybe this could help.  @xqt 18:02, 16 July 2017 (UTC)Reply
I solved the issue using pip install pywikibot ~ JoKalliauer (talk) 23:36, 14 July 2022 (UTC)Reply
This is always good enough if you have your own scripts based on pywikibot. If you want to use scripts shipped with pywikibot you have to clone/checkout the repository (either git or svn) or you can download the nightly from https://pywikibot.org. There are only some maintenance scripts which you can use if pywikibot is installed as a site-package like you did it. Refer https://doc.wikimedia.org/pywikibot/stable/utilities/scripts.html for the description.  @xqt 11:55, 22 July 2022 (UTC)Reply

PAWS commonscat error

edit

When in write pwb.py commonscat -start:Category:! -summary:Přidáno commonscat za použití bota it write this:

WARNING: CommonscatBot.__init__ set the Bot.site property; this is only needed when the Bot accesses many sites.

Retrieving 50 pages from wikipedia:cs.

>>> Kategorie:'s-Hertogenbosch <<<

Commonscat template is already on Kategorie:'s-Hertogenbosch

WARNING: API error mwoauth-invalid-authorization-invalid-user: The authorization headers in your request are for a user that does not exist here

0 pages read

0 pages written

Execution time: 1 seconds

Script terminated by exception:

ERROR: NoUsername: Failed OAuth authentication for commons:commons: The authorization headers in your request are for a user that does not exist

 here

Traceback (most recent call last):

  File "/srv/paws/pwb/pwb.py", line 263, in <module>

    if not main():

  File "/srv/paws/pwb/pwb.py", line 257, in main

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

  File "/srv/paws/pwb/pwb.py", line 121, in run_python_file

    main_mod.__dict__)

  File "/srv/paws/pwb/scripts/commonscat.py", line 549, in <module>

    main()

  File "/srv/paws/pwb/scripts/commonscat.py", line 541, in main

    bot.run()

  File "/srv/paws/pwb/pywikibot/bot.py", line 1525, in run

    super(Bot, self).run()

  File "/srv/paws/pwb/pywikibot/bot.py", line 1434, in run

    self.treat(page)

  File "/srv/paws/pwb/scripts/commonscat.py", line 254, in treat

    self.addCommonscat(page)

  File "/srv/paws/pwb/scripts/commonscat.py", line 305, in addCommonscat

    currentCommonscatTarget)

  File "/srv/paws/pwb/scripts/commonscat.py", line 453, in checkCommonscatLink

    commonsPage = pywikibot.Page(commonsSite, "Category:" + name)

  File "/srv/paws/pwb/pywikibot/tools/__init__.py", line 1448, in wrapper

    return obj(*__args, **__kw)

  File "/srv/paws/pwb/pywikibot/page.py", line 2179, in __init__

    super(Page, self).__init__(source, title, ns)

  File "/srv/paws/pwb/pywikibot/page.py", line 163, in __init__

    self._link = Link(title, source=source, defaultNamespace=ns)

  File "/srv/paws/pwb/pywikibot/page.py", line 5086, in __init__

    self._defaultns = self._source.namespaces[defaultNamespace]

  File "/srv/paws/pwb/pywikibot/site.py", line 1014, in namespaces

    self._namespaces = NamespacesDict(self._build_namespaces())

  File "/srv/paws/pwb/pywikibot/site.py", line 2612, in _build_namespaces

    is_mw114 = MediaWikiVersion(self.version()) >= MediaWikiVersion('1.14')

  File "/srv/paws/pwb/pywikibot/site.py", line 2725, in version

    version = self.siteinfo.get('generator', expiry=1).split(' ')[1]

  File "/srv/paws/pwb/pywikibot/site.py", line 1676, in get

    preloaded = self._get_general(key, expiry)

  File "/srv/paws/pwb/pywikibot/site.py", line 1622, in _get_general

    default_info = self._get_siteinfo(props, expiry)

  File "/srv/paws/pwb/pywikibot/site.py", line 1548, in _get_siteinfo

    data = request.submit()

  File "/srv/paws/pwb/pywikibot/data/api.py", line 2342, in submit

    self._data = super(CachedRequest, self).submit()

  File "/srv/paws/pwb/pywikibot/data/api.py", line 2175, in submit

    % (self.site, info))

pywikibot.exceptions.NoUsername: Failed OAuth authentication for commons:commons: The authorization headers in your request are for a user that

does not exist here

<class 'pywikibot.exceptions.NoUsername'>

CRITICAL: Closing network session. KlosseBot (talk) 14:48, 15 July 2017 (UTC)Reply

Seems the bot user does not exists.  @xqt 15:18, 15 July 2017 (UTC)Reply
But i login with this username. KlosseBot (talk) 15:55, 15 July 2017 (UTC)Reply
With what account do you use this script ? KlosseBot ? Framawiki (talk) 17:20, 15 July 2017 (UTC)Reply
It's probably phab:T136114. Framawiki (talk) 17:21, 15 July 2017 (UTC)Reply
Yes i use KlosseBot KlosseBot (talk) 17:25, 15 July 2017 (UTC)Reply

how can i get transclusions template

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 how can i get transclusions template using Pywikibot core? جار الله (talk) 20:26, 2 August 2017 (UTC)Reply

The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Moving pages

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.


Does movepages.py update redirects as well to avoid creating double redirects? Jc86035 (talk) 09:42, 13 August 2017 (UTC)Reply
Currently not.  @xqt 09:48, 13 August 2017 (UTC)Reply
Are there any scripts which do so? Jc86035 (talk) 10:00, 13 August 2017 (UTC)Reply
redirect.py XXN (talk) 10:55, 13 August 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Delay in movepages.py

edit

I am trying to delay movepages.py so it makes edits every eight seconds, so the script isn't stopped after every eight page moves by the Commons API. However, the script ignores user-config.py settings for delay since the action is not an edit but a page move. How can I add a delay? Jc86035 (talk) 13:08, 22 August 2017 (UTC)Reply

Please file a bug at [https://phabricator.wikimedia.org/maniphest/task/edit/form/1/?projects=PHID-PROJ-orw42whe2lepxc7gghdq phabricator]. Seems this is a real bug and should ne solved  @xqt 11:49, 23 August 2017 (UTC)Reply
Filed a bug, T173914. Jc86035 (talk) 12:02, 23 August 2017 (UTC)Reply

Pywikibot usage

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,

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?

Thanks!

Sami SamiIslam (talk) 11:38, 23 August 2017 (UTC)Reply

There is a script "pagefromfile.py" to do this but it is may be local community restrictions to allow or discard edits in this way.  @xqt 11:46, 23 August 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Uploading files with titles containing UTF-8 characters

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 was having trouble uploading python pwb.py upload.py -keep -noverify -ignorewarn "/…/BSicon hÜST.svg" narrow formations. Do I need to escape the Ü? Jc86035 (talk) 10:04, 10 September 2017 (UTC)Reply

No idea. A traceback would help to find out the problem.  @xqt 10:36, 10 September 2017 (UTC)Reply
(Third comment in thread; had previous revisions suppressed)
ERROR: Traceback (most recent call last):
 File "/…/Documents/pywikibot/pywikibot/data/api.py", line 1558, in submit
   body=body, headers=headers)
 File "/…/Documents/pywikibot/pywikibot/tools/__init__.py", line 1105, in wrapper
   return obj(*__args, **__kw)
 File "/…/Documents/pywikibot/pywikibot/comms/http.py", line 279, in request
   r = fetch(baseuri, method, body, headers, **kwargs)
 File "/…/Documents/pywikibot/pywikibot/comms/http.py", line 381, in fetch
   error_handling_callback(request)
 File "/…/Documents/pywikibot/pywikibot/comms/http.py", line 297, in error_handling_callback
   raise request.data
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 884: ordinal not in range(128)
Jc86035 (talk) 02:08, 11 September 2017 (UTC)Reply
Seems the traceback isn't complete. I propose to file a bug at phabricator: [1]  @xqt 10:49, 10 September 2017 (UTC)Reply
(I've tried changing multiple instances of "ascii" in the config files to "utf-8" but there was no effect.) Jc86035 (talk) 10:51, 10 September 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

wikidata is not valid site

edit
You are redefine your default mylang and family which is wikipedia:cs then.  @xqt 07:09, 16 September 2017 (UTC)Reply
How? Now i have just wikidata and still same response. KlosseBot (talk) 17:00, 16 September 2017 (UTC)Reply

Pagegenerator in different language.

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.


How i make pagegenerator for category on wikipedia in czech language? Walter Klosse (talk) 19:21, 18 October 2017 (UTC)Reply

Hello, do you want something like
python pwb.py replace "1" "2" -lang:cz -category:test
? Framawiki (talk) 20:31, 18 October 2017 (UTC)Reply
correct is -lang:cs Dvorapa (talk) 12:43, 22 October 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Replacing template with text

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,

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 ''replace.py'' (point 1 and 3), but I'm not sure it can do the 2nd; and it seems that ''template.py'' can only replace the template name.

Glz19 87.0.79.89 (talk) 14:58, 9 November 2017 (UTC)Reply

Try template.py script.  @xqt 15:00, 9 November 2017 (UTC)Reply
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. Glz19 (talk) 15:11, 9 November 2017 (UTC)Reply
All scripts have a documentation with it. Just use -help option. In your case -cat:<categoryname> should do it.  @xqt 15:19, 9 November 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

Why Pywikibot marks my edits as minor edits?

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 running Pywikibot/category.py at this moment, adding a category to a list of files.

I just noticed that the edits of my bot ( commons:Special:Contributions/Fructibot ) are marked as minor edits. Why is that and how can I fix it? Fructibus (talk) 06:23, 22 November 2017 (UTC)Reply

The reason is that bot edits normally should not be shown on user's watch list. This is done by this flag. The minor flag could be set on pywikibot.put() with minorEdit=False parameter or on pywikibot.save() method with minor=False parameter. But use it with care not to disturb other users flooding their watch lists.  @xqt 08:40, 22 November 2017 (UTC)Reply
Ahh, I see now, I was worried that maybe the robot is supposed to make normal edits, not minor edits, and therefore maybe I did something wrong. Thank you very much! Fructibus (talk) 11:50, 22 November 2017 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

How to disable "Sleeping for N seconds" on PyWikiBot

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.


How to disable "Sleeping for N seconds" on PyWikiBot 95.188.216.190 (talk) 14:13, 1 December 2017 (UTC)Reply

You shouldn't. This is necessary to throttle writing to the site high frequently and it is restricted on most wiki's.  @xqt 15:25, 1 December 2017 (UTC)Reply
Why you want to disable a security ? Not a good idea I think :) Framawiki (talk) 23:30, 1 December 2017 (UTC)Reply
Did you solved this?
https://github.com/donkaban/pywiki-bot/blob/master/user-config.py -- here you can see maxthrottle param and you can try to use it. But be carefull: throttle disabling can harm you wiki-server. Sergezolotukhin (talk) 08:25, 21 August 2018 (UTC)Reply
maxthrottle isn't the right parameter for that.  @xqt 10:06, 4 September 2018 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.
Return to "Pywikibot/2017" page.