在python 3中没有来自get请求站点的响应

时间:2018-04-12 08:39:26

标签: python-3.x get python-requests

此代码仅打印:

发送:b' GET /images/cms/thumbs/818029804609cbb6501795d736843e86c5e0051b/yacshik_orange_flowersbay1_370_370.jpg HTTP / 1.1

主持人:flowersbay.ru

User-Agent:python-requests / 2.18.4

接受: /

Accept-Encoding:gzip,deflate

连接:保持活力

import requests
import logging

try:
    import http.client as http_client
except ImportError:
    # Python 2
    import httplib as http_client
http_client.HTTPConnection.debuglevel = 1

# You must initialize logging, otherwise you'll not see debug output.
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
url = "https://flowersbay.ru/images/cms/thumbs/818029804609cbb6501795d736843e86c5e0051b/yacshik_orange_flowersbay1_370_370.jpg"
requests.get(url, verify=False, stream=True)

然后注意到,即使我等了很长时间。其他请求,例如https://de.fishki.net/picsw/062009/26/toys/014.jpg - 快速回应。

请你帮助我找到这种行为的原因吗?

1 个答案:

答案 0 :(得分:0)

显然,您尝试请求的网站阻止了针对http请求的python代理。 您需要在请求的标题中假冒浏览器,例如

url = "https://flowersbay.ru/images/cms/thumb/818029804609cbb6501795d736843e86c5e0051b/yacshik_orange_flowersbay1_370_370.jpg"
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} 
response = requests.get(url,headers=header)

这应该返回200 OK状态。