Python - 使用url超出最大重试次数(仅限生产服务器)

时间:2017-09-28 21:32:23

标签: python django

我试图连接到一个网页。这是我的代码:

class AddNewSite():

    def __init__(self, url, user=None, email=None, category=None, 
    subcategory=None, date_end=None):
        self.url = url
        self.user = user
        self.email = email
        req = Request(self.url, headers={'user-agent': 'Mozilla/5.0 
   (Macintosh; Intel Mac OS X 10_9_3) \
                AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 \
                Safari/537.36'})
        self.page = urlopen(req).read()
        self.soup = BeautifulSoup(self.page)
        self.meta = self.soup.find_all('meta')

在我的views.py(这是一个Django项目)中,我有:

try:
    page = AddNewSite(siteurl, user)
except Exception as e:
    print(e)
    messages.add_message(request, messages.ERROR,
                                 'ERROR')
            return render(request, 'mainapp/subcategory.html', context)

在localhost上一切正常。它连接到没有eny错误的站点。在生产服务器上,我得到一个例外。下面我从日志中粘贴错误。

HTTPConnectionPool(host='exeo.pl', port=80): Max retries exceeded with url: 
/ (Caused by 
NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection 
object at 0x80897ff98>: Failed to establish a new connection: [Errno 60] 
Operation timed out',))
HTTPConnectionPool(host='exeo.pl', port=80): Max retries exceeded with url: 
/ (Caused by 
NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection 
object at 0x80940aeb8>: Failed to establish a new connection: [Errno 60] 
Operation timed out',))
HTTPConnectionPool(host='exeo.pl', port=80): Max retries exceeded with url: 
/ (Caused by 
NewConnectionError('<requests.packages.urllib3.connection.HTTPConnection 
object at 0x80949fdd8>: Failed to establish a new connection: [Errno 60] 
Operation timed out',))
<urllib.request.Request object at 0x808b92048>

为什么问题仅存在于生产服务器上?

0 个答案:

没有答案