Current logic:
if config.fake_user_agent is None or config.fake_user_agent is True:
The value of config.fake_user_agent should either be True, False or an user-defined value. None is not needed here.
Current logic:
if config.fake_user_agent is None or config.fake_user_agent is True:
The value of config.fake_user_agent should either be True, False or an user-defined value. None is not needed here.
| Subject | Author | Repo | Branch | Lines +/- | |
|---|---|---|---|---|---|
| Improve fake user agent usage control | Dargasia | pywikibot/core | master | +186 -61 |
| Status | Subtype | Assigned | Task | ||
|---|---|---|---|---|---|
| Resolved | MtDu | T113596 reflinks.py work with old user agent | |||
| Resolved | Dargasea | T152075 Automatic use of fake user agent for bot-unfriendly sites |
The main problem is that the default is None in config2.py.
This task needs a little analysis to determine why the default is None, and what this currently does as the default for a user who doesnt modify this setting.
From memory, weblinkchecker.py needs user-agent faking to default to enabled, as many sites actively reject user-agents with bot-like parts, such as the string requests. (Ah, T71204: weblinkchecker.py uses a fake user-agent)
But we should not use a fake user-agent unless it is necessary.
From T71204, the second part wasnt done:
Faking the user-agent should be an option, default disabled, or only used for servers known to be problematic.
Maybe we need a list of servers that require a fake user-agent, so that it can be disabled by default in config2.py.
This task needs a little analysis to determine why the default is None
None behaves the same way as True (if set a value, UA becomes that value. if False, default UA returned). The default is Introduced since the patch was submitted and unchanged since then.
Potential actions:
I like these two combined:
i.e. we would add a use_fake_user_agent parameter to methods in http.comms, which is False by default, True forces a fake user-agent, and None means automatic use of fallback logic (use fake if in the config list, otherwise try with real user-agent, and fallback to fake).
Then we can remove the fake_user_agent config option.
That could be an extra feature.
It would also be nice if the config list allowed literal strings: when connecting to this server, use this user-agent, rather than a random one.
http.comms seems to be used only to get the user_agent, but not for making the requests themselves. Shouldn't this parameter and logic be implemented in the scripts that need fake UAs (i.e. reflinks and weblinkchecker) instead?
It would also be nice if the config list allowed literal strings: when connecting to this server, use this user-agent, rather than a random one.
Yup. This list would also be better if it is dynamically updated, instead of hard-coded in config2.py, so maybe we should put this on a WikiTech page. This make user-agent specifications like this less messy as well.
See pywikibot.comms.http.request
It would also be nice if the config list allowed literal strings: when connecting to this server, use this user-agent, rather than a random one.
Yup. This list would also be better if it is dynamically updated, instead of hard-coded in config2.py, so maybe we should put this on a WikiTech page. This make user-agent specifications like this less messy as well.
Nah, it should be part of the config, but at the end of a bot run it should warn the user that they should add the extra sites to the config.
We have been developing "loading config from the wiki", using JSON. I'll look into how that is going. We can continue with that after this task.
https://codein.withgoogle.com/tasks/4719662784839680/ will be the GCI task for this, when it is publish - waiting for admin to press the button
Update:
Maintain a list of problematic sites in the configuration file
This has been worked on, but:
automatic use of fallback logic
I am debating if this should be implemented. Currently I'm thinking of HTTP status codes, but I thought if a server returns something like 403 Forbidden, we should honour it instead. Also in T113596 the website returned 200, but with invalid content.
Unless there is a better way to detect failures, I'm considering submitting a first patch first, implementing per-module toggles (on/off for reflinks and weblinkchecker) and default behaviour exceptions (list of problematic sites part).
Currently I'm thinking of HTTP status codes, but I thought if a server returns something like 403 Forbidden, we should honour it instead.
Yea, that is reasonable.
Also in T113596 the website returned 200, but with invalid content.
Right, the user needs to explicitly add an entry; automatic fallback wont help with that one.
Unless there is a better way to detect failures
The best way to detect these websites is to try with the normal user-agent, then try a generated user-agent. The time to do this extra check is when the connection to the site is already established and open.
I'm considering submitting a first patch first, implementing per-module toggles .. and default behaviour exceptions ...
No worries splitting this into chunks, and stopping after each chunk to reconsider about whether it is wise to add more voodoo.
The first part is sufficient for a GCI task approval. I'm always happy to add more tasks to allow extra improvements to be done.
Change 325241 had a related patch set uploaded (by Dargasia):
Improve fake user agent usage control
Change 325241 abandoned by Dargasia:
Improve fake user agent usage control
Reason:
John: mistakes were made - screwed up my branch. Allow me some time to fix it. I'll start another Change later to make things less messy. Sorry for the trouble.
Change 325241 restored by John Vandenberg:
Improve fake user agent usage control
Reason:
no worries.
The biggest benefit of Gerrit is it is possible to re-do your branch.
If you add "Change-Id: I28594f" to your new commit message, on any branch, even with a different branch name, anywhere, git review will figure it all out magically.