There is a mediawiki_api_call who can make API requests with a better error handling. Move all the requests.get/post to mediawiki_api_call when possible.