[英]HTTP request via proxy on AWS server fails with 407
I'm running this brief script locally as well on an AWS EC2 intance in an ECS cluster: 我也在ECS集群中的AWS EC2实例上本地运行此简短脚本:
import requests
proxies = {'http':'http://user:pw@host:port','https':'http://user:pw@host:port'}
r = requests.get('http://quotes.toscrape.com/', proxies=proxies)
print r.status_code
When I run the script locally, I get a 200 status code, indicating that I successfully am able to connect to access the website via the proxy. 在本地运行脚本时,会收到200状态代码,表示我可以成功连接到代理服务器。
When I run the script on the AWS instance, I get a 407 proxy authentication error. 在AWS实例上运行脚本时,出现407代理身份验证错误。
This is a common error that others have experienced (eg see here ). 这是其他人遇到的常见错误(例如, 参见此处 )。 I'm looking for a solution that allows me to authenticate the proxies WITHOUT having to whitelist the instance. 我正在寻找一种解决方案,使我无需对实例进行白名单即可对代理进行身份验证。
The reason being is that every time I run a new instance, I'd have to whitelist that instance too. 原因是,每次运行新实例时,我也都必须将该实例列入白名单。 I would rather just pass in the credentials to requests and authenticate the proxy directly. 我宁愿只是将凭据传递给请求并直接对代理进行身份验证。
Is this possible? 这可能吗?
I would suggest you launch instances in the private subnet, and whitelist your NAT(s) EIP in this case you will only have to whitelist 1-4 IP addresses depending if you are using single NAT or a NAT per AZ (which is recommended). 我建议您在专用子网中启动实例,并将您的NAT EIP白名单,在这种情况下,您只需要将1-4个IP地址列入白名单,这取决于您是使用单个NAT还是每个AZ使用NAT(建议使用) 。
Hopefully, it does make sense, feel free to ask additional questions 希望这确实有意义,请随时提出其他问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.