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

Time:12-08

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

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 / like /AFLT.ME
  • to add slash / in the end like /AFLT.ME/

CodePudding user response:

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

  • Related