Working open_url().
authorCMDR furrycat <elite@furrycat.net>
Mon, 26 Sep 2016 13:00:42 +0000 (14:00 +0100)
committerCMDR furrycat <elite@furrycat.net>
Mon, 26 Sep 2016 13:00:42 +0000 (14:00 +0100)
bot.py

diff --git a/bot.py b/bot.py
index f51b6cb..df303ec 100755 (executable)
--- 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!')