Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python requests.get(URL) returns 404 error when using URL with dot

I’m trying to get webpage https://finance.yahoo.com/quote/AFLT.ME using Requests library for Python.

This link opens well in browser, but results in Error 404 while using this code:

import requests
r = requests.get('https://finance.yahoo.com/quote/AFLT.ME')

I’m pretty sure that the problem is in the dot (.) symbol in the "AFLT.ME" as code works well with URLs without dot – for example https://finance.yahoo.com/quote/AAPL

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I already have found answers solving this problem BUT on website owner side.

But how can I solve this issue doing GET requests?

I have tried some advises that unfortunately DID NOT help:

  • to replace dot . with %2f like /AFLT%2EME
  • to add slash / in the end like /AFLT.ME/

>Solution :

Strange, it seems that if one sends the User-Agent header, even with an empty value, it then responds with a 200:

>>> requests.get('https://finance.yahoo.com/quote/AFLT.ME', headers={'User-Agent': ''})
<Response [200]>

Edit: The same issue was reported here: https://stackoverflow.com/a/68259438/9835872

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading