You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python requests请求戴尔页面返回403,浏览器可正常访问

解决戴尔支持页面Requests请求403状态码问题

以下是针对该问题的几种可行解决方案:

1. 使用会话保持Cookie上下文

戴尔的特定服务标签页面可能需要验证浏览器会话中的Cookie,直接请求目标页面会被反爬机制拦截。先访问首页获取必要Cookie,再通过会话请求目标页面:

import requests

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36'
}

# 初始化会话,自动管理Cookie
session = requests.Session()
# 先访问首页获取会话Cookie
session.get('https://www.dell.com/support/home/en-us?lwp=rt', headers=headers)
# 携带Cookie请求目标页面
response = session.get('https://www.dell.com/support/home/en-us/product-support/servicetag/0-ek1RYjR0NnNuandqYVQ1NjdUMm9IZz090/overview', headers=headers)
print(response.status_code)

2. 简化请求头字段

手动复制的请求头包含部分浏览器专属字段(如sec-ch-ua系列、authority),requests库会自动处理这些字段,强行设置可能触发反爬。只保留关键标识字段即可:

headers = {
    'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
    'accept-language': 'en-US;q=0.9,en;q=0.8'
}

3. 更新依赖库以兼容TLS版本

Python 3.7.3搭配的旧版本requests/urllib3可能不支持戴尔服务器要求的TLS协议版本,导致请求被拒绝。执行以下命令更新依赖:

pip install --upgrade requests urllib3

4. 补充请求上下文字段

部分网站会验证请求的来源上下文,可在请求头中添加referer字段指向首页,模拟浏览器的跳转逻辑:

headers['referer'] = 'https://www.dell.com/support/home/en-us?lwp=rt'

内容的提问来源于stack exchange,提问作者Artyrm Sergeev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 08:30:36