summaryrefslogtreecommitdiff
path: root/crocoite
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2018-04-14 14:17:03 +0200
committerLars-Dominik Braun <lars@6xq.net>2018-04-14 14:17:42 +0200
commit048085595975b02389e8d58ed74e5a18573ee569 (patch)
tree8424445b0558fb35c00b44e3214a0d172f13948a /crocoite
parent45ddbd8f74aa624cdb0714db88e133bf4f92e702 (diff)
downloadcrocoite-048085595975b02389e8d58ed74e5a18573ee569.tar.gz
crocoite-048085595975b02389e8d58ed74e5a18573ee569.tar.bz2
crocoite-048085595975b02389e8d58ed74e5a18573ee569.zip
Add timeout to request body fetch
When something goes wrong, these block the entire grab.
Diffstat (limited to 'crocoite')
-rw-r--r--crocoite/browser.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/crocoite/browser.py b/crocoite/browser.py
index 260e061..744d064 100644
--- a/crocoite/browser.py
+++ b/crocoite/browser.py
@@ -25,6 +25,7 @@ Chrome browser interactions.
import logging
from urllib.parse import urlsplit
from base64 import b64decode
+import pychrome
class Item:
"""
@@ -68,7 +69,7 @@ class Item:
def body (self):
""" Return response body or None """
try:
- body = self.tab.Network.getResponseBody (requestId=self.id)
+ body = self.tab.Network.getResponseBody (requestId=self.id, _timeout=60)
rawBody = body['body']
base64Encoded = body['base64Encoded']
if base64Encoded:
@@ -76,7 +77,7 @@ class Item:
else:
rawBody = rawBody.encode ('utf8')
return rawBody
- except pychrome.exceptions.CallMethodException:
+ except (pychrome.exceptions.CallMethodException, pychrome.exceptions.TimeoutException):
return None
def setRequest (self, req):
@@ -360,7 +361,7 @@ def NullService (url):
### tests ###
-import unittest, pychrome, time
+import unittest, time
from http.server import BaseHTTPRequestHandler
class TestHTTPRequestHandler (BaseHTTPRequestHandler):