"How do I resolve the 'HTTP 403: Forbidden' error?"
"How do I resolve the 'HTTP 403: Forbidden' error?"
我正尝试在 google colab 中 运行 这段代码,但是,我得到 "HTTP Error 403: Forbidden":
import six.moves.urllib as urllib
try:
import urllib.request
except ImportError:
raise ImportError('You should use Python 3.x')
if not os.path.exists('./RoadDamageDataset.tar.gz'):
url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz'
urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz')
print("Download RoadDamageDataset.tar.gz Done")
else:
print("You have RoadDamageDataset.tar.gz")
HTTPError Traceback (most recent call last)
<ipython-input-16-99e6ecabe7df> in <module>()
6 if not os.path.exists('./RoadDamageDataset.tar.gz'):
7 url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz'
----> 8 urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz')
9
10 print("Download RoadDamageDataset.tar.gz Done")
6 frames
/usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
648 class HTTPDefaultErrorHandler(BaseHandler):
649 def http_error_default(self, req, fp, code, msg, hdrs):
--> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp)
651
652 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden
任何帮助将不胜感激。(link 到 google 驱动器中的代码:https://drive.google.com/file/d/1C-_DBepoJFL5HztTyYx9uNG22_MJB5Bo/view?usp=sharing)
我冒昧修改了你的主题行:你问的主要问题是"How do I resolve the 'HTTP 403: Forbidden' error?"。我还冒昧修改了你的标签:你的语言是Python;您正在导入 "six" 库,并且您正在使用 Google Colaboratory。
无论如何:
https://en.wikipedia.org/wiki/HTTP_403
HTTP 403 provides a distinct error case from HTTP 401; while HTTP 401
is returned when the client has not authenticated, and implies that a
successful response may be returned following valid authentication,
HTTP 403 is returned when the client is not permitted access to the
resource despite providing authentication such as insufficient
permissions of the authenticated account.
请记住,Web 服务器(此处为 Google Colab)在某些 "user" 的上下文中运行。我猜您的文件 (RoadDamageDataset.tar.gz) 可能没有网络用户的读取权限。
建议:确认 /RoadDamageDataset.tar.gz
具有 "read" 权限。
此外,这看起来不对:
url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz'
urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz')
建议:尝试将其更改为https://s3-ap-northeast-1.amazonaws.com/mycityreport
我正尝试在 google colab 中 运行 这段代码,但是,我得到 "HTTP Error 403: Forbidden":
import six.moves.urllib as urllib
try:
import urllib.request
except ImportError:
raise ImportError('You should use Python 3.x')
if not os.path.exists('./RoadDamageDataset.tar.gz'):
url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz'
urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz')
print("Download RoadDamageDataset.tar.gz Done")
else:
print("You have RoadDamageDataset.tar.gz")
HTTPError Traceback (most recent call last)
<ipython-input-16-99e6ecabe7df> in <module>()
6 if not os.path.exists('./RoadDamageDataset.tar.gz'):
7 url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz'
----> 8 urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz')
9
10 print("Download RoadDamageDataset.tar.gz Done")
6 frames
/usr/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
648 class HTTPDefaultErrorHandler(BaseHandler):
649 def http_error_default(self, req, fp, code, msg, hdrs):
--> 650 raise HTTPError(req.full_url, code, msg, hdrs, fp)
651
652 class HTTPRedirectHandler(BaseHandler):
HTTPError: HTTP Error 403: Forbidden
任何帮助将不胜感激。(link 到 google 驱动器中的代码:https://drive.google.com/file/d/1C-_DBepoJFL5HztTyYx9uNG22_MJB5Bo/view?usp=sharing)
我冒昧修改了你的主题行:你问的主要问题是"How do I resolve the 'HTTP 403: Forbidden' error?"。我还冒昧修改了你的标签:你的语言是Python;您正在导入 "six" 库,并且您正在使用 Google Colaboratory。
无论如何:
https://en.wikipedia.org/wiki/HTTP_403
HTTP 403 provides a distinct error case from HTTP 401; while HTTP 401 is returned when the client has not authenticated, and implies that a successful response may be returned following valid authentication, HTTP 403 is returned when the client is not permitted access to the resource despite providing authentication such as insufficient permissions of the authenticated account.
请记住,Web 服务器(此处为 Google Colab)在某些 "user" 的上下文中运行。我猜您的文件 (RoadDamageDataset.tar.gz) 可能没有网络用户的读取权限。
建议:确认 /RoadDamageDataset.tar.gz
具有 "read" 权限。
此外,这看起来不对:
url_base = 'https://s3-ap-northeast-1.amazonaws.com/mycityreport/RoadDamageDataset.tar.gz'
urllib.request.urlretrieve(url_base, './RoadDamageDataset.tar.gz')
建议:尝试将其更改为https://s3-ap-northeast-1.amazonaws.com/mycityreport