请求:请求永远不会在Windows机器上终止

时间:2018-04-24 00:55:03

标签: python windows python-3.x request

我遇到的问题是,在运行Python 3.6.3的AWS EC2 Windows Server计算机上无法执行简单的GET HTTP请求:

import requests
requests.get('http://some_picture_url')

该命令永远不会在Windows机器上终止。我可以在同一台机器上的Internet Explorer中检索图像。

我该如何调试?其他网址工作正常。

1 个答案:

答案 0 :(得分:0)

我假设您的要求是将图像提取到服务器。由于您可以通过资源管理器访问该图像,因此我们可以排除任何阻止访问的防火墙/安全组。

您可以在机器中试用以下脚本吗

import shutil
import requests

url = 'https://www.gstatic.com/webp/gallery3/1.png'
response = requests.get(url, stream=True)
with open('1.png', 'wb') as out_file:
    shutil.copyfileobj(response.raw, out_file)
del response

为了调试网址,我建议您检查网址回复。

import requests
r = requests.get('https://www.gstatic.com/webp/gallery3/1.png')
print(r.status_code)
相关问题