I have the following url link which has accented charaters:
https://www.janes.com/...tamandaré... etc.
When I try to request the link, I get the error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 89: invalid continuation byte
This is my code:
import requests
def request_site(url):
return requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0)'})
if __name__ == '__main__':
url = 'https://www.janes.com/article/87665/laad-2019-united-kingdom-s-sea-signs-mou-with-brazilian-siatt-for-tamandaré-class-corvette-torpedo-tubes'
print(request_site(url))
The full error:
Traceback (most recent call last):
File "D:/OneDrive/PhD/Web Crawler/playground.py", line 104, in <module>
print(request_site(url))
File "D:/OneDrive/PhD/Web Crawler/playground.py", line 73, in request_site
return requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0)'})
File "C:\Python35\lib\site-packages\requests\api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "C:\Python35\lib\site-packages\requests\api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "C:\Python35\lib\site-packages\requests\sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python35\lib\site-packages\requests\sessions.py", line 668, in send
history = [resp for resp in gen] if allow_redirects else []
File "C:\Python35\lib\site-packages\requests\sessions.py", line 668, in <listcomp>
history = [resp for resp in gen] if allow_redirects else []
File "C:\Python35\lib\site-packages\requests\sessions.py", line 149, in resolve_redirects
url = self.get_redirect_target(resp)
File "C:\Python35\lib\site-packages\requests\sessions.py", line 115, in get_redirect_target
return to_native_string(location, 'utf8')
File "C:\Python35\lib\site-packages\requests\_internal_utils.py", line 25, in to_native_string
out = string.decode(encoding)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 89: invalid continuation byte
I found many questions (like link) that are similar, but non of them propose a solution for the same problem, as well as, all of the previous solutions are for python2.