jenkins-bot has submitted this change and it was merged.
Change subject: User-agent should work when the site is None ......................................................................
User-agent should work when the site is None
Change-Id: I802bd54def87069b1a205cd0f563081a629ac1fb --- M pywikibot/comms/http.py 1 file changed, 17 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index d5bbd20..0390486 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -144,15 +144,23 @@ baseuri = urlparse.urljoin("%(proto)s://%(host)s" % locals(), uri) else: baseuri = uri - username = site.username() - if not username: - username = "" - kwargs["headers"]["user-agent"] = config.USER_AGENT_FORMAT.format( - script=pywikibot.calledModuleName(), - version=pywikibot.version.getversiondict()['rev'], - username=quote(username), - lang=site.code, - family=site.family.name) + if "headers" not in kwargs: + kwargs["headers"] = {} + if site: + username = site.username() + if not username: + username = "" + kwargs["headers"]["user-agent"] = config.USER_AGENT_FORMAT.format( + script=pywikibot.calledModuleName(), + version=pywikibot.version.getversiondict()['rev'], + username=quote(username), + lang=site.code, + family=site.family.name) + else: + USER_AGENT_FORMAT = '{script}/{version} Pywikibot/2.0' + kwargs["headers"]["user-agent"] = USER_AGENT_FORMAT.format( + script=pywikibot.calledModuleName(), + version=pywikibot.version.getversiondict()['rev']) request = threadedhttp.HttpRequest(baseuri, *args, **kwargs) http_queue.put(request) while not request.lock.acquire(False):
pywikibot-commits@lists.wikimedia.org