From f6ef64a034318e61806d6e61df39a0abbcedc681 Mon Sep 17 00:00:00 2001 From: Sandro-Alessio Gierens Date: Tue, 28 Nov 2023 10:02:25 +0100 Subject: [PATCH 1/2] feat(autoload): add user-agent to urllib requests to avoid http 403 Signed-off-by: Sandro-Alessio Gierens --- autoload/rfc.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/autoload/rfc.vim b/autoload/rfc.vim index 365e862..ae73d2e 100644 --- a/autoload/rfc.vim +++ b/autoload/rfc.vim @@ -93,10 +93,20 @@ function! s:open_entry_by_cr() endfunction python3 << EOF +def _build_req(url): + from urllib.request import Request + return Request( + url, + data=None, + headers={ + 'User-Agent': 'Mozilla/5.0 (compatible; vim-rfc)', + } + ) + def fetch_rfc(url): import urllib.request try: - rfc = urllib.request.urlopen(url).read().decode('utf-8').splitlines() + rfc = urllib.request.urlopen(_build_req(url)).read().decode('utf-8').splitlines() except urllib.request.URLError as e: print(f'{e}\nFetching RFC failed. Connected to the internet? Behind proxy?') return False @@ -111,7 +121,7 @@ def create_cache_file(): import xml.etree.ElementTree as ET try: - xml = urllib.request.urlopen('https://www.rfc-editor.org/in-notes/rfc-index.xml').read() + xml = urllib.request.urlopen(_build_req('https://www.rfc-editor.org/rfc-index.xml')).read() except urllib.error.URLError as e: print(f'{e}\nFetching RFC index failed. Connected to the internet? Behind proxy?') return False From c8c61a2dc86c30a9328a510f755b18553deaf7f7 Mon Sep 17 00:00:00 2001 From: Sandro-Alessio Gierens Date: Tue, 28 Nov 2023 10:03:41 +0100 Subject: [PATCH 2/2] style(autoload): remove trailing space Signed-off-by: Sandro-Alessio Gierens --- autoload/rfc.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/rfc.vim b/autoload/rfc.vim index ae73d2e..fab320b 100644 --- a/autoload/rfc.vim +++ b/autoload/rfc.vim @@ -11,7 +11,7 @@ if !has('win32') endif function! rfc#query(create_cache_file, query) abort - if !s:has_python3 + if !s:has_python3 echomsg 'vim-rfc: This plugin requires +python3 support for :python3 and py3eval().' if has('nvim') echomsg 'Run ":checkhealth provider" for further diagnosis.'