0

我对这个问题有同样的问题: Python requests.get 失败,禁止 403,即使在使用标头和 Session 对象之后

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

我试过了:

Python 请求 - 403 被禁止 - 尽管设置了 `User-Agent` 标头

和 :

Python 请求。403 禁止

有人知道解决它的另一种选择吗?

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)
4

2 回答 2

1

For someone who is having the same problem , the solution to my problem was to fill in the cookers information in the headers.

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':" ..."}

You can get the cookie info in same way as useg-agent as explained here

Python requests. 403 Forbidden

于 2021-11-18T13:35:06.637 回答
0

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

于 2021-11-16T15:57:44.800 回答