From d2f59ef8925d988942abd7c10731b45f5878217b Mon Sep 17 00:00:00 2001 From: songhm Date: Mon, 14 Jan 2019 22:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/phone_conf.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/config/phone_conf.py b/config/phone_conf.py index a207148..b26b563 100644 --- a/config/phone_conf.py +++ b/config/phone_conf.py @@ -1,18 +1,16 @@ # -*- coding: utf8 -*- __author__ = 'Song' -import urllib2 +import requests from config.ticketConf import _get_yaml from config.TicketEnmu import ticket def send_request(url): if not url: - return 'error' - req = urllib2.Request(url) - req.add_header('User-Agent', - 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16') + raise ValueError('error') + headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16'} try: - response = urllib2.urlopen(req, timeout=3) + response = requests.get(url, headers=headers, timeout=3) except Exception as e: return e result = response.read()