403 forbidden(Spider error)

这里写图片描述

(To ensure the safety, edit some words.)
When I run a spider on Taobao get the error 403.

As the above page image, it receive the response successfully.
But if you open the request url on a new web, it will receive 403 forbidden, I do not know what happened there.

I try imitate the request by using postman but also got the 403.

After that, I found that some params like :authority:scheme and these things make me find that postman not support http2, so I try make it by python requests.

Then an error occured. I throw the symbol colon, then get the real response.

There are still something make me boring.
Anyway, I make it.

Finally, show you the code:

import requests

url = "https://detailskip.taobao.com/service/getData/1/p1/item/detail/sib.htm"

querystring = {"itemId":"537337861521","sellerId":"1096320518","modules":"dynStock,qrcode,viewer,price,contract,duty,xmpPromotion,delivery,upp,activity,fqg,zjys,amountRestriction,couponActivity,soldQuantity,tradeContract","callback":"onSibRequestSuccess"}

headers = {
    'x-requested-with': "XMLHttpRequest",
    'accept': "*/*",
    'accept-encoding': "gzip, deflate, sdch, br",
    'accept-language': "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4",
    'cookie': "thw=cn; t=91a9f63dff91a1c00e8552a2229bf49f; cookie2=1cb5763df4cb43b824eb1fcd18; v=0; cna=; _tb_token_=04eeb53d3511; uc1=cookie14=UoW%2Bvf0NDvrQ%3D%3D; l=AsbGqOOlKA9YtY278R47/14olrdIygrl; isg=Ah4epUtxy28OGB8NkAaMWo4rb7SeFuJZFy2HfMinZ2FY67zFMG_naHjLhUWa",
    'referer': "https://item.taobao.com/item.htm?spm=a21fg.7938700.204843.1.sGwL2B&scm=1007.12144.81309.2193_1158&pvid=4fad7005-d521-4b2a-a27f-dc3d3bb3e557&id=532801124551",
    'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36",
    'authority':"detailskip.taobao.com",
    'method':"GET",
    'path':"/service/getData/1/p1/item/detail/sib.htm?itemId=532801124551&sellerId=367896056&modules=dynStock,qrcode,viewer,price,contract,duty,xmpPromotion,delivery,upp,activity,fqg,zjys,couponActivity,soldQuantity,tradeContract&callback=onSibRequestSuccess",
    'scheme':"https",
    'cache-control': "no-cache",
    'postman-token': "32d300ff-08db-6069-bde5-9d8e091915d1"
    }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)
HTTP 403 Forbidden错误通常表示服务器收到了请求,但是拒绝执行这个请求。这可能是由于以下几个原因: 1. **权限不足**:你可能试图访问的内容或资源是你没有权限访问的,比如某些页面仅限于特定用户或IP地址。 2. **配置限制**:服务器的`.htaccess`文件(在Apache web服务器中常见)可能设置了访问控制规则,不允许某些路径或URL的访问。 3. **目录锁定**:有时服务器上的某个目录被设置为只读模式,不接受写入或执行操作,这也会导致403 Forbidden。 4. **安全设置**:防火墙或安全软件可能会阻止某些请求,尤其是在云环境中。 在你的案例中[^1],当你遇到403 Forbidden错误时,修改`.htaccess`文件并上传成功解决了问题,这表明可能是文件权限设置不当或者是基于规则的访问控制策略发生了改变。 要解决这类问题,你可以尝试以下步骤: 1. **确认权限**:检查是否有正确的权限访问该资源,可能需要与网站管理员联系以获得必要的访问权限。 2. **查看.htaccess**:查看或理解`.htaccess`文件中关于访问控制的部分,看看是否存在误操作或过时的规则。 3. **清除缓存**:有时候,浏览器缓存也可能导致显示旧的访问权限设置,清空浏览器缓存试试看。 4. **重置服务器设置**:如果上述方法无效,可能需要联系服务器提供商,让他们帮助检查或调整服务器设置。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值