forked from openlp/openlp
Specify OpenLP as the user agent when querying SF.net
This commit is contained in:
parent
60b7f2dbbd
commit
a023e63f21
@ -45,7 +45,7 @@ from openlp.core.lib import translate, PluginStatus, Receiver, build_icon, \
|
||||
check_directory_exists
|
||||
from openlp.core.lib.settings import Settings
|
||||
from openlp.core.utils import get_web_page, AppLocation, join_url, \
|
||||
get_filesystem_encoding
|
||||
get_filesystem_encoding, get_application_version
|
||||
from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -106,7 +106,8 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
|
||||
# url is defined in 'download.cfg' file.
|
||||
self.baseurl = None
|
||||
# Check to see if we have web access
|
||||
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg'))
|
||||
user_agent = u'OpenLP/' + get_application_version()[u'version']
|
||||
self.webAccess = get_web_page(u'%s%s' % (self.web, u'download.cfg'), header=(u'User-Agent', user_agent))
|
||||
if self.webAccess:
|
||||
files = self.webAccess.read()
|
||||
self.config.readfp(io.BytesIO(files))
|
||||
|
@ -493,11 +493,11 @@ def get_web_page(url, header=None, update_openlp=False):
|
||||
if not url:
|
||||
return None
|
||||
req = urllib2.Request(url)
|
||||
user_agent = _get_user_agent()
|
||||
log.debug(u'Using user agent: %s', unicode(user_agent))
|
||||
req.add_header('User-Agent', user_agent)
|
||||
if header:
|
||||
req.add_header(header[0], header[1])
|
||||
if not header or header[0].lower() != u'user-agent':
|
||||
user_agent = _get_user_agent()
|
||||
req.add_header('User-Agent', str(user_agent))
|
||||
elif header:
|
||||
req.add_header(str(header[0]), str(header[1]))
|
||||
page = None
|
||||
log.debug(u'Downloading URL = %s' % url)
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user