From: CMDR furrycat Date: Mon, 26 Sep 2016 13:00:42 +0000 (+0100) Subject: Working open_url(). X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=31af6f9f7cd86cadc70ff24c7ead99b91f1949fe;p=furrycat%2Fcatbot.git Working open_url(). --- diff --git a/bot.py b/bot.py index f51b6cb..df303ec 100755 --- a/bot.py +++ b/bot.py @@ -50,7 +50,7 @@ greetings = [ def open_url(url): if sys.version_info >= (3, 0): # Specify our own user agent as Cloudflare doesn't seem to like the urllib one - request = urllib.request.Request(url, headers={'User-Agent': USER_AGENT}) + request = urllib.request.Request(url, headers={'User-Agent': 'catbot'}) try: return urllib.request.urlopen(request) except urllib.error.HTTPError as err: @@ -62,7 +62,7 @@ def open_url(url): if platform.system() == 'Darwin' and ssl.OPENSSL_VERSION_INFO[0] < 1: sslctx.set_ciphers("ECCdraft:HIGH:!aNULL") # Specify our own user agent as Cloudflare doesn't seem to like the urllib one - request = urllib2.Request(url, headers={'User-Agent': USER_AGENT}) + request = urllib2.Request(url, headers={'User-Agent': 'catbot'}) try: return urllib2.urlopen(request, context=sslctx) except urllib2.HTTPError as err: @@ -129,7 +129,7 @@ def do_admin(message, command, raw): log.debug('No URL for avatar') yield from say(message.channel, 'zzz') return - fd = util.open_url(url) + fd = open_url(url) if fd is None: log.debug('Failed to open URL {} for avatar'.format(url)) yield from say(message.channel, 'yelp!')