I am trying to get the following URL with requests.get()
in Python 3.x: http://www.finanzen.net/suchergebnis.asp?strSuchString=DE0005933931 (this URL consists of a base URL with the search string DE0005933931
).
The request gets redirected (via HTTP status code 301) to http://www.finanzen.net/etf/ishares_core_dax%AE_ucits_etf_de in a browser (containing the character 0xAE character ® in the URL). Using requests.get()
with the redirected URL works as well.
When trying to get the search string URL with Python 2.7 everything works and I get the redirected response, using Python 3.x I get the following error:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 21: invalid start byte
The code snippet to test this:
import requests
url_1 = 'http://www.finanzen.net/suchergebnis.asp?strSuchString=LU0274208692'
# redirected to http://www.finanzen.net/etf/db_x-trackers_msci_world_index_ucits_etf_1c
url_2 = 'http://www.finanzen.net/suchergebnis.asp?strSuchString=DE0005933931'
# redirected to http://www.finanzen.net/etf/ishares_core_dax%AE_ucits_etf_de
print(requests.get(url_1).status_code) # working
print(requests.get(url_2).status_code) # error with Python 3.x
Some more information:
- I am working on Windows 7 using Python 3.6.3 with
requests.__version__ = '2.18.4'
but I get the same error with other Python versions as well (3.4, 3.5). - Using other search strings, everything works with Python 3.x as well, e.g. http://www.finanzen.net/suchergebnis.asp?strSuchString=LU0274208692
- Interestingly I even get an
Internal Server Error
with https://www.hurl.it trying to GET the above mentioned URL. Maybe it is no Python problem.
Any idea, why this is working in Python 2.7 but not in Python 3.x and what I can do about this?