forked from alexz-enwp/wikitools
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Hi, I am still trying to migrate a python 2.7 script to python3, using wikitools3, as in issues #8 and #9. in fact I now using the local branch I made that seems to fix my problem in #9.
This time my script is also attempting to access a page from my wiki :
#!/usr/bin/env python
""" quick and dirty script aimed at debugging wikitools3 """
""" see issues https://github.com/mediawiki-client-tools/wikitools3/issues """
import os
from wikitools3 import wiki, page
# now I am using my company's wiki api
api_url = os.environ.get('WIKI_URL')
username = os.environ.get('WIKI_USER')
password = os.environ.get('WIKI_PASSWORD')
print("api_url: " + str(api_url) + " username: " + username)
if not password:
print("Empty variable: WIKI_PASSWORD")
sys.exit(1)
site = wiki.Wiki(api_url, username, password, True)
# This "Test title" page does not exist but I get the same result with existing titles
p = page.Page(site, "Test title")It fails like this:
Traceback (most recent call last):
File "./test_wikitools.py", line 17, in <module>
p = page.Page(site, "test title")
File "/workdir/wikitools3/page.py", line 132, in __init__
self.setPageInfo()
File "/workdir/wikitools3/page.py", line 169, in setPageInfo
self.pageid = response["query"]["pages"].keys()[0]
TypeError: 'dict_keys' object is not subscriptable
I suggest the following patch for page.py line 169:
req = api.APIRequest(self.site, params)
response = req.query(False)
- self.pageid = response["query"]["pages"].keys()[0]
+ self.pageid = int(list(response["query"]["pages"].keys())[0])
if self.pageid > 0:
self.exists = True
The call to list() solves the TypeError: 'dict_keys' object is not subscriptable, and the call to int() averts a TypeError: '>' not supported between instances of 'str' and 'int' at line 170.
Metadata
Metadata
Assignees
Labels
No labels