Python curl获取响应403 我怎样才能绕过403码?
我试图从一个网站上获取搜索结果,但是我收到了“Response[403]”消息,我发现类似的get解决403错误的方法是在request.get中添加标题,但是它对我的问题不起作用。我应该怎么做才能正确地得到我想要的结果 谷歌浏览器请求 请求Python curl获取响应403 我怎样才能绕过403码?,python,python-3.x,python-2.7,http-status-code-403,http-response-codes,Python,Python 3.x,Python 2.7,Http Status Code 403,Http Response Codes,我试图从一个网站上获取搜索结果,但是我收到了“Response[403]”消息,我发现类似的get解决403错误的方法是在request.get中添加标题,但是它对我的问题不起作用。我应该怎么做才能正确地得到我想要的结果 谷歌浏览器请求 请求 Request URL: http://178.32.46.165/ Request Method: GET Status Code: 200 OK Remote Address: 178.32.46.165:80 Referrer Policy: str
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]>
如果收到403响应,您可能无法访问此资源。这不是Python的问题,这是您试图访问的任何网站的问题
此外,这似乎是一个暂时的问题。我将您的代码按原样粘贴到我的Python提示符中,并收到
我认为它可能会根据国家/地区提供阻止功能。OP可能因为不旋转代理/用户代理而被阻止-这可能是它对您有效的原因。仅供参考@YunusK