From 3883a1d6a24fbe99f96258342e4197172a06e200 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 26 Feb 2011 20:39:35 -0500 Subject: [PATCH] Make user agent consistant. Remove debugging code. --- src/calibre/__init__.py | 5 +++-- src/calibre/gui2/store/web_control.py | 16 +++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 221f5911c6..61b8bd36f8 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -240,6 +240,8 @@ def get_parsed_proxy(typ='http', debug=True): prints('Using http proxy', str(ans)) return ans +USER_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101210 Gentoo Firefox/3.6.13' +USER_AGENT_MOBILE = 'Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/20060610 Minimo/0.016' def browser(honor_time=True, max_time=2, mobile_browser=False, user_agent=None): ''' @@ -254,8 +256,7 @@ def browser(honor_time=True, max_time=2, mobile_browser=False, user_agent=None): opener.set_handle_refresh(True, max_time=max_time, honor_time=honor_time) opener.set_handle_robots(False) if user_agent is None: - user_agent = ' Mozilla/5.0 (Windows; U; Windows CE 5.1; rv:1.8.1a3) Gecko/20060610 Minimo/0.016' if mobile_browser else \ - 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101210 Gentoo Firefox/3.6.13' + user_agent = USER_AGENT_MOBILE if mobile_browser else USER_AGENT opener.addheaders = [('User-agent', user_agent)] http_proxy = get_proxies().get('http', None) if http_proxy: diff --git a/src/calibre/gui2/store/web_control.py b/src/calibre/gui2/store/web_control.py index 3b6337f597..d679d2d45d 100644 --- a/src/calibre/gui2/store/web_control.py +++ b/src/calibre/gui2/store/web_control.py @@ -8,19 +8,20 @@ from cookielib import Cookie, CookieJar from PyQt4.Qt import QWebView, QWebPage, QNetworkCookieJar, QNetworkRequest, QString +from calibre import USER_AGENT + class NPWebView(QWebView): def __init__(self, *args): QWebView.__init__(self, *args) self.gui = None - #self.setPage(NPWebPage()) + self.setPage(NPWebPage()) self.page().networkAccessManager().setCookieJar(QNetworkCookieJar()) self.page().setForwardUnsupportedContent(True) self.page().unsupportedContent.connect(self.start_download) self.page().downloadRequested.connect(self.start_download) self.page().networkAccessManager().sslErrors.connect(self.ignore_ssl_errors) - #self.page().networkAccessManager().finished.connect(self.fin) def createWindow(self, type): if type == QWebPage.WebBrowserWindow: @@ -33,7 +34,6 @@ class NPWebView(QWebView): def start_download(self, request): if not self.gui: - print 'no gui' return url = unicode(request.url().toString()) @@ -41,13 +41,7 @@ class NPWebView(QWebView): def ignore_ssl_errors(self, reply, errors): reply.ignoreSslErrors(errors) - - def fin(self, reply): - if reply.error(): - print 'error' - print reply.error() - #print reply.attribute(QNetworkRequest.HttpStatusCodeAttribute).toInt() - + def get_cookies(self): cj = CookieJar() @@ -99,4 +93,4 @@ class NPWebView(QWebView): class NPWebPage(QWebPage): def userAgentForUrl(self, url): - return 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.102 Safari/534.13' + return USER_AGENT