779 Star 1.5K Fork 351

开源中国 / Gitee Feedback

 / 详情

urlopen 获取 gitee page 的静态资源出现 403

已拒绝
缺陷(Bug)
创建于  
2020-12-04 15:50

问题描述

我用 python 3 的 urlopen 来获取 gitee page 中的远程数据时出现"urllib.error.HTTPError: HTTP Error 403: Forbidden";同样情况下,获取 github page 远程数据时显示是正常的。请问这是 gitee 做了什么操作吗?怎么样才能实现类似 github page 的效果?

重现步骤

Python 3.6.10 (default, Jun  3 2020, 09:40:13)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from urllib.request import urlopen
>>> path_or_url="https://usegalaxy-cn.gitee.io/res/test-data/heatmap/heatmap-test.tab"
>>> urlopen(path_or_url)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/software/python-3.6/lib/python3.6/urllib/request.py", line 223, in urlopen
    return opener.open(url, data, timeout)
  File "/data/software/python-3.6/lib/python3.6/urllib/request.py", line 532, in open
    response = meth(req, response)
  File "/data/software/python-3.6/lib/python3.6/urllib/request.py", line 642, in http_response
    'http', request, response, code, msg, hdrs)
  File "/data/software/python-3.6/lib/python3.6/urllib/request.py", line 570, in error
    return self._call_chain(*args)
  File "/data/software/python-3.6/lib/python3.6/urllib/request.py", line 504, in _call_chain
    result = func(*args)
  File "/data/software/python-3.6/lib/python3.6/urllib/request.py", line 650, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
>>> urlopen("https://shenweiyan.github.io/startbootstrap-creative/assets/img/bg-masthead.jpg")
<http.client.HTTPResponse object at 0x7f9a548e2e48>
>>>

期望效果

希望 gitee page 能和 github page 一样,使用相同的方法获取静态资源时,不会出现额外的异常。

实际效果

评论 (2)

WeiYanCC 创建了缺陷
WeiYanCC 关联仓库设置为开源中国/Gitee Feedback
诺墨 添加协作者诺墨
展开全部操作日志

这个问题什么时候可以帮忙确认一下,谢谢!@诺墨 @atompi

诺墨 负责人设置为atompi
诺墨 取消协作者诺墨

我们对某些特定 UA 做了屏蔽,目的是为了防止恶意引用外链,同时避免不必要的法律纠纷。对于有外链需求的用户,建议使用 CDN 。Python-urllib 在屏蔽列表中。

atompi 任务状态待确认 修改为已完成
atompi 任务状态已完成 修改为已拒绝
诺墨 将工作项从 缺陷 迁移到 缺陷(Bug)
诺墨 任务类型缺陷 修改为缺陷(Bug)

登录 后才可以发表评论

状态
负责人
项目
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
预计工期 (小时)
参与者(2)
1268058 shenweiyan 1578947766 1034229 atompi 1578938786
Ruby
1
https://gitee.com/oschina/git-osc.git
git@gitee.com:oschina/git-osc.git
oschina
git-osc
Gitee Feedback

搜索帮助