Branch: refs/heads/master Author: Enrico Tröger enrico.troeger@uvena.de Committer: Enrico Tröger enrico.troeger@uvena.de Date: Sat, 01 Feb 2014 13:11:25 UTC Commit: 39f13cb3b6a47e535a04385a0d2207bcec9fce87 https://github.com/geany/infrastructure/commit/39f13cb3b6a47e535a04385a0d220...
Log Message: ----------- Send a specific user-agent to tiny.cc as they seem to block urllib's default
For some reason, tiny.cc started to block requests with the user-agent "Python-urllib/2.7" which is the default of the urllib module. Using any other user-agent works so we send our own including a link to the script's source code.
Modified Paths: -------------- scripts/git2irc/git2irc.py
Modified: scripts/git2irc/git2irc.py 8 files changed, 6 insertions(+), 2 deletions(-) =================================================================== @@ -46,7 +46,7 @@
from cgi import FieldStorage from json import loads -from urllib2 import urlopen +from urllib2 import urlopen, Request from urllib import urlencode import logging import logging.handlers @@ -63,6 +63,9 @@ # extend on demand LOG_EMAIL_ADDRESSES = ['enrico@geany.org']
+# user-agent to be used for requests to tiny.cc +USER_AGENT = u'git2irc.py - https://raw.github.com/geany/infrastructure/master/scripts/git2irc/git2irc.p...' + # global and cuts across concerns, assumed to be properly initialized later logger = None # see init_logging() config = {'git': {}, 'irc': {}, 'shortener': {}} # see init_config() @@ -135,8 +138,9 @@ def shorten_url(long_url): req_enc = urlencode(req) req_url = '%s?%s' % (config['shortener']['url'], req_enc) short_url = long_url # default is to return same URL (ie. in case of error) + request = Request(req_url, headers={"User-Agent": USER_AGENT}) try: - resp_file = urlopen(req_url) + resp_file = urlopen(request) resp_dict = loads(resp_file.read()) if int(resp_dict['errorCode']) == 0: short_url = resp_dict['results']['short_url']
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).