Add HTTP User-Agent header to API calls
See original GitHub issueAccording to the MediaWiki API docs, there should be an HTTP User-Agent header added to API calls. We should follow the policy by adding a user agent to our HTTP GET calls.
Probably something like the following should do it (reference):
import wikipron
import requests
HTTP_HEADERS = {
"User-Agent": (
f"WikiPron/{wikipron.__version__} "
"(https://github.com/kylebgorman/wikipron) "
f"requests/{requests.__version__}"
),
}
requests.get(..., headers=HTTP_HEADERS)
I think there are only two places in the codebase where a requests.get
call (or equivalent) is made:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
User-Agent - HTTP - MDN Web Docs - Mozilla
The User-Agent request header is a characteristic string that lets servers and network peers identify the application, operating system, ...
Read more >HTTP headers | User-Agent - GeeksforGeeks
The HTTP headers User-Agent is a request header that allows a characteristic string that allows network protocol peers to identify the ...
Read more >RESTful API: require user agent string? - Stack Overflow
Since the User-Agent header is not absolutely required to be present within HTTP requests (the spec says the header SHOULD be there, ...
Read more >Set a custom user agent | New Relic Documentation
When using New Relic's RESTful APIs, set a User-Agent header that identifies your integration in API calls. This custom User-Agent string allows New...
Read more >How to add User-Agent header to HttpClient in .NET
This article will introduce you to the format for the User-Agent HTTP header as well as how to add it in various ways...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There are three GET calls to Wiktionary in
data/src/codes.py
: https://github.com/kylebgorman/wikipron/blob/ac821c5d0a7d70e7e700f45f9d01b2dfb4ecae9d/data/src/codes.py#L61 https://github.com/kylebgorman/wikipron/blob/ac821c5d0a7d70e7e700f45f9d01b2dfb4ecae9d/data/src/codes.py#L86 https://github.com/kylebgorman/wikipron/blob/ac821c5d0a7d70e7e700f45f9d01b2dfb4ecae9d/data/src/codes.py#L110 Do we need a User-Agent header for these as well?Hi @Alireza-Sampour , thank you for your interest in contributing! I just found two more spots – I forgot about
tests/
:https://github.com/kylebgorman/wikipron/blob/fab40759d4fc95579769f44a9decf1c087771e75/tests/test_wikipron/test_config.py#L193
https://github.com/kylebgorman/wikipron/blob/fab40759d4fc95579769f44a9decf1c087771e75/tests/test_wikipron/__init__.py#L16
We can probably define the
HTTP_HEADERS
dict just once, inwikipron/srape.py
. Then we can use it directly for the first and second locations I’ve mentioned above. For the third case intests/test_wikipron/test_config.py
,HTTP_HEADERS
could be imported through this line. For the fourth case intests/test_wikipron/__init__.py
, I believe we could dofrom wikipron.scrape import HTTP_HEADERS
just before this line – I was thinking through and trying to see if we’d run into surprises like circular imports, ending up typing all this out…Here are the notes for contributors.