简体   繁体   中英

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

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/

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM