In playing with direct dial I found I setup the user-agent incorrectly
[gc-dialer] / src / backends / browser_emu.py
index b676a13..5e9b678 100644 (file)
@@ -36,8 +36,19 @@ _moduleLogger = logging.getLogger(__name__)
 socket.setdefaulttimeout(45)
 
 
+def add_proxy(protocol, url, port):
+       proxyInfo = "%s:%s" % (url, port)
+       proxy = urllib2.ProxyHandler(
+               {protocol: proxyInfo}
+       )
+       opener = urllib2.build_opener(proxy)
+       urllib2.install_opener(opener)
+
+
 class MozillaEmulator(object):
 
+       USER_AGENT = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729)'
+
        def __init__(self, trycount = 1):
                """Create a new MozillaEmulator object.
 
@@ -132,6 +143,7 @@ class MozillaEmulator(object):
                        'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png',
                        'Accept-Language': 'en,en-us;q=0.5',
                        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
+                       'User-Agent': self.USER_AGENT,
                }
                for key, value in extraheaders.iteritems():
                        txheaders[key] = value
@@ -153,10 +165,6 @@ class MozillaEmulator(object):
                        urllib2.HTTPCookieProcessor(self._cookies),
                        redirector
                )
-               u.addheaders = [(
-                       'User-Agent',
-                       'Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4 (.NET CLR 3.5.30729)'
-               )]
                if not postdata is None:
                        req.add_data(postdata)
                return (req, u)