home
·
contact
·
privacy
projects
/
plomlombot-irc.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
2fc56d6
)
Handle URLs for too large websites / files.
author
Christian Heller
<c.heller@plomlompom.de>
Mon, 18 Apr 2016 20:45:37 +0000
(22:45 +0200)
committer
Christian Heller
<c.heller@plomlompom.de>
Mon, 18 Apr 2016 20:45:37 +0000
(22:45 +0200)
plomlombot.py
patch
|
blob
|
history
diff --git
a/plomlombot.py
b/plomlombot.py
index 7224b29e2ccff2a90504a113676edd625278253e..aa7061cac656f3f6b5f768e40787ccb6fbc475c4 100755
(executable)
--- a/
plomlombot.py
+++ b/
plomlombot.py
@@
-339,17
+339,22
@@
def handle_url(url, notice, show_url=False):
return True
try:
return True
try:
- r = requests.get(url, timeout=15)
+ r = requests.get(url, timeout=5, stream=True)
+ r.raw.decode_content = True
+ text = r.raw.read(10000000+1)
+ if len(text) > 10000000:
+ raise ValueError('Too large a response')
except (requests.exceptions.TooManyRedirects,
requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL,
UnicodeError,
except (requests.exceptions.TooManyRedirects,
requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL,
UnicodeError,
+ ValueError,
requests.exceptions.InvalidSchema) as error:
notice("TROUBLE FOLLOWING URL: " + str(error))
return
if mobile_twitter_hack(url):
return
requests.exceptions.InvalidSchema) as error:
notice("TROUBLE FOLLOWING URL: " + str(error))
return
if mobile_twitter_hack(url):
return
- title = bs4.BeautifulSoup(
r.
text, "html5lib").title
+ title = bs4.BeautifulSoup(text, "html5lib").title
if title and title.string:
prefix = "PAGE TITLE: "
if show_url:
if title and title.string:
prefix = "PAGE TITLE: "
if show_url: