Python请求-禁止的错误(目录问题,即../还原)

时间:2019-01-07 09:25:36

标签: python python-requests

代码

hostDir = 'https://www.example.com/a/b/'
path = '../../script.js'
x = hostDir + path
import requests
print(requests.get(x).content.decode('utf-8'))

当我运行上面的代码时,它给出以下错误:

<HTML><HEAD>
<TITLE>Access Denied</TITLE>
</HEAD><BODY>
<H1>Access Denied</H1>

You don't have permission to access "http&#58;&#47;&#47;www&#46;xyz&#46;com&#47;a&#47;b&#47;&#46;&#46;&#47;&#46;&#46;&#47;script&#46;js" on this server.<P>
Reference&#32;&#35;18&#46;3da21ab8&#46;1546852663&#46;7da6a685
</BODY>
</HTML>

我可以看到此问题是由于路径'../../'和'/ a / b /'引起的,但是请求模块无法将其转换为'https://www.example.com/scripts.js'

同时考虑“ ../../”和“ / a / b /”的次数。

请帮助我解决该问题,以便将其转换为“ https://www.example.com/scripts.js

0 个答案:

没有答案