mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-12 18:24:58 +08:00
Exception free retrieve_url()
Set 2 second timeout and handle any possible connection error Return empty string to engine in case of connection exception
This commit is contained in:
parent
167d20083d
commit
86a0eaf317
@ -22,7 +22,7 @@
|
|||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#VERSION: 1.34
|
#VERSION: 1.40
|
||||||
|
|
||||||
# Author:
|
# Author:
|
||||||
# Christophe DUMEZ (chris@qbittorrent.org)
|
# Christophe DUMEZ (chris@qbittorrent.org)
|
||||||
@ -65,7 +65,11 @@ def htmlentitydecode(s):
|
|||||||
def retrieve_url(url):
|
def retrieve_url(url):
|
||||||
""" Return the content of the url page as a string """
|
""" Return the content of the url page as a string """
|
||||||
req = urllib2.Request(url, headers = headers)
|
req = urllib2.Request(url, headers = headers)
|
||||||
|
try:
|
||||||
response = urllib2.urlopen(req)
|
response = urllib2.urlopen(req)
|
||||||
|
except urllib2.URLError as errno:
|
||||||
|
print(" ".join(("Connection error:", str(errno.reason))))
|
||||||
|
return ""
|
||||||
dat = response.read()
|
dat = response.read()
|
||||||
# Check if it is gzipped
|
# Check if it is gzipped
|
||||||
if dat[:2] == '\037\213':
|
if dat[:2] == '\037\213':
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
# POSSIBILITY OF SUCH DAMAGE.
|
# POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
#VERSION: 1.35
|
#VERSION: 1.40
|
||||||
|
|
||||||
# Author:
|
# Author:
|
||||||
# Christophe DUMEZ (chris@qbittorrent.org)
|
# Christophe DUMEZ (chris@qbittorrent.org)
|
||||||
@ -65,7 +65,11 @@ def htmlentitydecode(s):
|
|||||||
def retrieve_url(url):
|
def retrieve_url(url):
|
||||||
""" Return the content of the url page as a string """
|
""" Return the content of the url page as a string """
|
||||||
req = urllib.request.Request(url, headers = headers)
|
req = urllib.request.Request(url, headers = headers)
|
||||||
|
try:
|
||||||
response = urllib.request.urlopen(req)
|
response = urllib.request.urlopen(req)
|
||||||
|
except urllib.error.URLError as errno:
|
||||||
|
print(" ".join(("Connection error:", str(errno.reason))))
|
||||||
|
return ""
|
||||||
dat = response.read()
|
dat = response.read()
|
||||||
# Check if it is gzipped
|
# Check if it is gzipped
|
||||||
if dat[:2] == b'\x1f\x8b':
|
if dat[:2] == b'\x1f\x8b':
|
||||||
|
Loading…
Reference in New Issue
Block a user