【问题标题】:curl get response 403卷曲得到响应 403
【发布时间】:2021-01-03 16:10:26
【问题描述】:

如何绕过 403 代码?

我试图从一个网站获取搜索结果,但是我收到“响应 [403]”消息,我发现通过向 request.get 添加标头来解决 403 错误,但它不适用于我的问题。我应该怎么做才能正确得到我想要的结果?

谷歌浏览器请求

请求

Request URL: http://178.32.46.165/
Request Method: GET
Status Code: 200 OK
Remote Address: 178.32.46.165:80
Referrer Policy: strict-origin-when-cross-origin

请求标头

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: tr-TR,tr;q=0.9
Cache-Control: max-age=0
Connection: keep-alive
Host: 178.32.46.165
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36

Python 请求

import requests

headers = {
    'Connection': 'keep-alive',
    'Cache-Control': 'max-age=0',
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
    'Accept-Language': 'tr-TR,tr;q=0.9',
}

response = requests.get('http://178.32.46.165/', headers=headers, verify=False)
print(response)

回应

<Response [403]>

【问题讨论】:

    标签: python python-3.x python-2.7 http-status-code-403 http-response-codes


    【解决方案1】:

    如果您收到 403 响应,您可能无法访问此资源。这不是 Python 问题,这是您尝试访问的任何网站的问题。

    此外,这似乎是一个临时问题。我将您的代码按原样粘贴到我的 Python 提示符中并收到 &lt;Response [200]&gt;

    【讨论】:

    • OP 有可能因为没有轮换代理/用户代理而被阻止 - 这可能就是它对您有用的原因。仅供参考@YunusK
    【解决方案2】:

    我认为它可能会根据国家/地区提供屏蔽。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-07
      • 1970-01-01
      • 2019-10-14
      • 2015-07-31
      • 1970-01-01
      相关资源
      最近更新 更多