卷曲获取响应403

时间:2020-09-16 19:15:47

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

如何解决403代码?

我试图从网站上获取搜索结果,但是收到“ Response [403]”消息,我发现通过向header.get添加标头也可以解决403错误,但是对我来说不起作用问题。我应该怎么做才能正确获得想要的结果?

Google Chrome请求

请求

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]>

2 个答案:

答案 0 :(得分:0)

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

此外,这似乎是暂时的问题。我将您的代码原样粘贴到Python提示符中,并收到了<Response [200]>

答案 1 :(得分:0)

我认为可能会因国家/地区而有所不同。

相关问题