我正在尝试编写一些自动化程序,以便从实例中获取激活密钥,并在AWS上激活一个存储网关。我一直在python 3.6的AWS Lambda中使用"requests“库来写这篇文章,结果只是遇到了以下问题:
Your web browser must have JavaScript enabled每当我执行get请求时都会出错。然而,在他们的文档中:
它们使用wget向实例发出请求,并获得带有激活密钥的响应。Wget没有javascript解释器,这是怎么工作的呢?
这是不是可以直接通过python实现,或者我只能下载像selenium或phantomjs这样的胖二进制文件,将其解压到zip文件中,然后上传该zip文件,以便发出一个包含javascript的web请求?
发布于 2019-01-11 02:21:03
Curl安装在lambda上。我能够使用curl实现这一点。
def get_gateway_activation_key(event):
print("Getting activation key...")
fgs = event["ResourceProperties"]["FileGatewayOptions"]["FileGatewaySettings"]
url = "redirect_url=$(curl -f -s -S -w '%%{redirect_url}' \"http://%s/?activationRegion=%s\") && echo $redirect_url" % (fgs["InstanceIP"],fgs["GatewayRegion"])
redirect_url = os.popen(url).read()
if redirect_url == "" or redirect_url is None:
raise Exception("No redirect url returned for ip: %s" % fgs["InstanceIP"])
key = redirect_url.split("activationKey=")[1].split("&gateway")[0]
if key is None or key is "":
raise Exception("Unable to extract the key from the returned redirect url: %s" %redirect_url)
print("Retrieved Activation Key: %s" % key)
return keyhttps://stackoverflow.com/questions/54132285
复制相似问题