【问题标题】:Python-requests-get-fails-with-403-forbidden-even-after-using-headers-and-session - PYTHON 3.8Python-requests-get-fails-with-403-forbidden-even-after-using-headers-and-session - PYTHON 3.8
【发布时间】:2021-12-27 17:01:10
【问题描述】:

我对这个问题有同样的问题: Python requests.get fails with 403 forbidden, even after using headers and Session object

不幸的是没有答案。那么我该如何解决禁止的403?

我试过了:

Python requests - 403 forbidden - despite setting `User-Agent` headers

和:

Python requests. 403 Forbidden

有人知道解决它的另一种方法吗?

import requests

url_complete='https://smartsub.les.inf.puc-rio.br//media/imagens/5f667ec98b21262d4fc0a9dc5df4d0e4/8c6bbb5844e009eab139442e4024684d.jpg'


session = requests.Session()
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53',
          'referer':'https://smartsub.les.inf.puc-rio.br/login/?next=/'}
Picture_request = session.get(url_complete,headers=headers)
print(Picture_request)

【问题讨论】:

    标签: python python-requests http-status-code-403


    【解决方案1】:

    对于遇到相同问题的人,我的问题的解决方案是在标题中填写炊具信息。

    headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53',
    
    'cookie':" ..."}
    

    您可以使用与此处说明的 useg-agent 相同的方式获取 cookie 信息

    Python requests. 403 Forbidden

    【讨论】:

      【解决方案2】:

      尝试使用 HTTP 代理,例如“Zyte”

      【讨论】:

      • 感谢您的回复,但我不明白。你能再具体一点吗?我到底需要改变什么?
      • 您需要在 GET 请求中实现代理解决方案。检查此链接:zyte.com/smart-proxy-manager
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 2022-12-02
      • 2018-10-01
      • 1970-01-01
      相关资源
      最近更新 更多