Manual talk:Pywikibot

Jump to: navigation, search

About this board

Archives 


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.

By clicking "Add topic", you agree to our Terms of Use and agree to irrevocably release your text under the CC BY-SA 3.0 License and GFDL
KlosseBot (talkcontribs)

When i wrote pwb.py login -all it write

*.wikidata is not a valid site, please remove it from your config

Traceback (most recent call last):

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

    if not main():

  File "/srv/paws/pwb/pwb.py", line 255, 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/login.py", line 190, in <module>

    main()

  File "/srv/paws/pwb/scripts/login.py", line 163, in main

    for familyName in namedict:

RuntimeError: dictionary changed size during iteration

<class 'RuntimeError'>

CRITICAL: Closing network session.

In user-config.py file i have

mylang = "wikidata" 

family = "wikidata" 

mylang = "cs"

family = "wikipedia" 

Xqt (talkcontribs)

You are redefine your default mylang and family which is wikipedia:cs then.

KlosseBot (talkcontribs)

How? Now i have just wikidata and still same response.

Reply to "wikidata is not valid site"

Uploading files with titles containing UTF-8 characters

5
Jc86035 (talkcontribs)

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 Ü?

Xqt (talkcontribs)

No idea. A traceback would help to find out the problem.

Jc86035 (talkcontribs)

(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)
Xqt (talkcontribs)

Seems the traceback isn't complete. I propose to file a bug at phabricator:

Jc86035 (talkcontribs)

(I've tried changing multiple instances of "ascii" in the config files to "utf-8" but there was no effect.)

KlosseBot (talkcontribs)

CMD writing no module named pywikibot when i start login.py

Xqt (talkcontribs)

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

2A00:1028:9192:FA72:F903:A911:3814:C073 (talkcontribs)

And when i write python pwb.py login it said no module named request.

Xqt (talkcontribs)

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

188.23.125.244 (talkcontribs)

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.

Framawiki (talkcontribs)

Hello, can you type python pwb.py version and post here what you obtain ?

188.23.125.244 (talkcontribs)

This doesn't even work for me, as it gets an error in line 163 of pwb.py

Xqt (talkcontribs)

Did you installed requests for both python releases?

88.117.63.15 (talkcontribs)

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.

KlosseBot (talkcontribs)

'pip install requests' doesnt work

Xqt (talkcontribs)

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.

KlosseBot (talkcontribs)

I have 3.4 but still it isnt pip in it. How do i install it?

Xqt (talkcontribs)

Maybe this could help.

Reply to "No module named pywikibot"
Jc86035 (talkcontribs)

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?

Xqt (talkcontribs)

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

Jc86035 (talkcontribs)

Filed a bug, T173914.

Reply to "Delay in movepages.py"
SamiIslam (talkcontribs)

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

Xqt (talkcontribs)

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.

Reply to "Pywikibot usage"
Jc86035 (talkcontribs)

Does movepages.py update redirects as well to avoid creating double redirects?

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

Currently not.

Jc86035 (talkcontribs)

Are there any scripts which do so?

XXN (talkcontribs)

redirect.py

Reply to "Moving pages"

how can i get transclusions template

1
جار الله (talkcontribs)

Hello how can i get transclusions template using Pywikibot core?

KlosseBot (talkcontribs)

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.

Xqt (talkcontribs)

Seems the bot user does not exists.

KlosseBot (talkcontribs)

But i login with this username.

Framawiki (talkcontribs)

With what account do you use this script ? KlosseBot ?

Framawiki (talkcontribs)

It's probably phab:T136114.

KlosseBot (talkcontribs)

Yes i use KlosseBot

Reply to "PAWS commonscat error"
Aschroet (talkcontribs)

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?

Xqt (talkcontribs)

replace.py could do it:

pwb.py replace -regex ".*" "Any text you want to have on this page" -page:user:Aschroet/sandbox

Xqt (talkcontribs)

Better use:

pwb.py replace -regex "(?s).+" "Any text you want to have on this page" -page:user:Aschroet/sandbox

Aschroet (talkcontribs)

Thank you. A batch replacement is not possible, or?

Xqt (talkcontribs)

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.

Reply to "Replace the whole text"
ChongDae (talkcontribs)

I'm porting my script from trunk to rewrite branch. How can I create item in wikidata?

Legoktm (talkcontribs)
import pywikibot
site = pywikibot.Site('en', 'wikipedia')
repo = site.data_repository()

data = {'sitelinks': {'site':'enwiki', 'title':'Main Page'}}
something = repo.editEntity({}, data, bot=True)
print something

It is in the roadmap to make this an ItemPage constructor in the future.

Edoderoo (talkcontribs)

thanks... been looking a while for this!

Reply to "createitem in rewrite branch"