From 531e4473ccfc214cb30582905b7dea23d011d501 Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Mon, 16 Nov 2015 05:57:20 +0100 Subject: [PATCH] Specify a custom user-agent string for all default requests. --- manga/htcache.py | 3 ++- manga/lib.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/manga/htcache.py b/manga/htcache.py index 45ede5d..5f28c00 100644 --- a/manga/htcache.py +++ b/manga/htcache.py @@ -11,7 +11,8 @@ class cache(object): return n.hexdigest() def miss(self, url): - with urllib.request.urlopen(url) as s: + req = urllib.request.Request(url, headers={"User-Agent": "automanga/1"}) + with urllib.request.urlopen(req) as s: if s.headers.get("content-encoding") == "gzip": import gzip, io return gzip.GzipFile(fileobj=io.BytesIO(s.read()), mode="r").read() diff --git a/manga/lib.py b/manga/lib.py index c0a9f30..662ecc3 100644 --- a/manga/lib.py +++ b/manga/lib.py @@ -160,7 +160,9 @@ class stdimgstream(imgstream): def __init__(self, url): import urllib.request - self.bk = urllib.request.urlopen(url) + req = urllib.request.Request(url, headers={"User-Agent": "automanga/1"}) + print(req) + self.bk = urllib.request.urlopen(req) ok = False try: if self.bk.getcode() != 200: -- 2.11.0