简体   繁体   English

Python requests.get(URL) 在使用带点的 URL 时返回 404 错误

[英]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.我正在尝试使用 Python 的请求库来获取网页https://finance.yahoo.com/quote/AFLT.ME

This link opens well in browser, but results in Error 404 while using this code:此链接在浏览器中打开良好,但在使用此代码时导致错误 404:

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我很确定问题出在“AFLT.ME”中的点 (.) 符号中,因为代码适用于不带点的 URL - 例如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%2f类似 /AFLT%2EME
  • to add slash / in the end like /AFLT.ME/添加斜线/最后像 /AFLT.ME/

Strange, it seems that if one sends the User-Agent header, even with an empty value, it then responds with a 200:奇怪的是,似乎如果发送User-Agent header,即使是空值,它也会响应 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编辑:这里报告了同样的问题: https://stackoverflow.com/a/68259438/9835872

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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