Jump to content

Manual talk:Pywikibot/2018

Add topic
From mediawiki.org
Latest comment: 6 years ago by Framawiki in topic Some issues


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.

Pagefromfile requires additional login

[edit]

When I try to create a webpage on a 3rd party wiki using the pagefromfile script, it required me to log into my bot account a second time despite being already logged in (I used the python pwb.py login -sysop command prior),

The bot also has the proper rights to write/read a page on the wiki.

The page will properly post once I manually put in the bot password but if possible I would like to automate the process so that it does not require any input after calling the Pagefromfile function.

The paramters I am currently using are -file, -begin, -end, -notitle, -force.

The bot can use other functions such as weblinkchecker without requesting me to log in a second time 148.177.1.215 (talk) 19:26, 16 January 2018 (UTC)Reply

3 Warnings

[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've written a script whose goal is to write the population for https://www.wikidata.org/wiki/Q985476 (only at the moment) per year, which can be found here: https://drive.google.com/drive/folders/1s5ypAGF3u_PGtj9gyIkR7v0CCWdHBUNy?usp=sharing. When running the script I actually get 3 Warnings;

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

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

WARNING: /home/edson/Bureau/core/pywikibot/site.py:1331: 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 "pwb.py", line 263, in <module>

   if not main():

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

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

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

   main_mod.__dict__)

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

   populationClaim.addQualifier(qualifier)

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

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

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

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

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

   data = req.submit()

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

   raise APIError(**result['error'])

pywikibot.data.api.APIError: noclaim: The "claim" parameter must be set. [help:See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/mailman/listinfo/mediawiki-api-announce&gt; for notice of API deprecations and breaking changes.]

<class 'pywikibot.data.api.APIError'>

CRITICAL: Closing network session.

What am I doing wrong? Soued031 (talk) 14:37, 18 January 2018 (UTC)Reply

@Matěj Suchánek Dvorapa (talk) 14:56, 18 January 2018 (UTC)Reply
How does your code look like? Matěj Suchánek (talk) 17:19, 18 January 2018 (UTC)Reply
@Matěj Suchánek It's on the google drive link mentioned above https://drive.google.com/drive/folders/1s5ypAGF3u_PGtj9gyIkR7v0CCWdHBUNy?usp=sharing. Soued031 (talk) 17:35, 18 January 2018 (UTC)Reply
Oops, I see now.
The solution is to move the bottom line (item.addClaim) just before # add qualifier to claim. Matěj Suchánek (talk) 17:55, 18 January 2018 (UTC)Reply
@Matěj Suchánek Great it works! Thanks for the fast answer. Do I need to do something special to ask for bot rights? Soued031 (talk) 18:42, 18 January 2018 (UTC)Reply
If you want to run a bot on Wikidata, I strongly recommend you requesting the flag at d:WD:RFBOT. Matěj Suchánek (talk) 18:54, 18 January 2018 (UTC)Reply
Thanks I will look at it. Soued031 (talk) 19:04, 18 January 2018 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

removing references from wikidata doesn't work

[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 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: https://drive.google.com/drive/folders/1SgQym9-Gv0FGKw8tUuUyDEIIViEN_Eak?usp=sharing Soued031 (talk) 09:40, 24 January 2018 (UTC)Reply

The docstring of Claim.removeSources says: @type sources: list of pywikibot.Claim, which item.claims['P1082'][i].sources is not. That is a list of key: list of pywikibot.Claim mappings. Matěj Suchánek (talk) 14:57, 24 January 2018 (UTC)Reply
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? Soued031 (talk) 15:32, 24 January 2018 (UTC)Reply
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():
        sources.extend(value)
item.removeSources(sources)
Matěj Suchánek (talk) 15:53, 24 January 2018 (UTC)Reply
Thanks a lot your code snippet works! Soued031 (talk) 16:02, 24 January 2018 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.

redirect.py Login Failed (Aborted)

[edit]

Hello,

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

When I try to use redirect.py 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 login.py script.

Thanks for the help 148.177.1.215 (talk) 14:42, 5 February 2018 (UTC)Reply

Hello, can you copy/paste the full shell history somewhere, like on https://tools.wmflabs.org/paste/ ? Framawiki (talk) 21:53, 7 February 2018 (UTC)Reply
Thanks for the help,
here is the shell history after I ran the redirect.py command.
https://tools.wmflabs.org/paste/view/7003368e
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). 148.177.1.215 (talk) 14:48, 9 February 2018 (UTC)Reply

Deleting blank lines with replace.py inside templates

[edit]

Hello! I have been using replace.py 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! Theklan (talk) 22:07, 27 May 2018 (UTC)Reply

Please share more information: What is your regex, what does your input look like, what do you expect? Matěj Suchánek (talk) 06:52, 28 May 2018 (UTC)Reply
Look for example to the source code here: https://eu.wikipedia.org/wiki/Acantholytoceras. I'm trying to change /n/n/n for /n/n, and it looks like I can delete some lines, but evidently not all of them. Theklan (talk) 07:07, 28 May 2018 (UTC)Reply
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. Matěj Suchánek (talk) 07:16, 28 May 2018 (UTC)Reply
Thanks for the clue! Is there any other script to delete blank lines only inside templates? Theklan (talk) 07:18, 28 May 2018 (UTC)Reply
None that I know. Matěj Suchánek (talk) 07:28, 28 May 2018 (UTC)Reply

Some issues

[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.


when I run welcome.py, it returns:

Traceback (most recent call last):

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

   if not main():

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

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

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

   main_mod.__dict__)

  File ".\scripts\welcome.py", line 880, in <module>

   main()

  File ".\scripts\welcome.py", line 859, in main

   bot.run()

  File ".\scripts\welcome.py", line 611, in run

   for users in self.parseNewUserLog():

  File ".\scripts\welcome.py", line 563, in parseNewUserLog

   yield pywikibot.User(ue.page())

  File "D:\Pywikibot\core-aoa-zh\pywikibot\logentries.py", line 122, in page

   self._page = pywikibot.Page(self.site, self.data['title'])

  File "D:\Pywikibot\core-aoa-zh\pywikibot\logentries.py", line 34, in __missing__

   raise KeyError("Log entry (%s) has no '%s' key" % (self._type, key))

KeyError: "Log entry (newusers) has no 'title' key"

<class 'KeyError'>

CRITICAL: Closing network session. Angrydog001 (talk) 15:38, 22 December 2018 (UTC)Reply

What should I do? Angrydog001 (talk) 15:39, 22 December 2018 (UTC)Reply
File this bug to phabricator  @xqt 16:07, 22 December 2018 (UTC)Reply
Hi Angrydog001, please fill a ticket on phab phab:/project/view/87/, with the command you entered to start the script, the full traceback present in your last message and the output of `python pwb.py version` command. Framawiki (talk) 14:27, 26 December 2018 (UTC)Reply
The discussion above is closed. Please do not modify it. No further edits should be made to this discussion.