PhantomJS don't load mobile.twitter.com via Selenium
Question: My configuration - _Selenium 2.44.0 + Python 3.4.2 + PhantomJS 2.0.0 (on
Windows 7 x64)_. I try to load <https://mobile.twitter.com> from Python
program using PhantomJS WebDriver and I get error message:

    
    
    Traceback (most recent call last):
      File "C:\Python\Python342x64\myprog\code.py", line 11, in <module>
        browser.get('https://mobile.twitter.com/')
      File "C:\Python\Python342x64\lib\site-packages\selenium-2.44.0-py3.4.egg\selenium\webdriver\remote\webdriver.py", line 185, in get
        self.execute(Command.GET, {'url': url})
      File "C:\Python\Python342x64\lib\site-packages\selenium-2.44.0-py3.4.egg\selenium\webdriver\remote\webdriver.py", line 171, in execute
        response = self.command_executor.execute(driver_command, params)
      File "C:\Python\Python342x64\lib\site-packages\selenium-2.44.0-py3.4.egg\selenium\webdriver\remote\remote_connection.py", line 349, in execute
        return self._request(command_info[0], url, body=data)
      File "C:\Python\Python342x64\lib\site-packages\selenium-2.44.0-py3.4.egg\selenium\webdriver\remote\remote_connection.py", line 417, in _request
        resp = opener.open(request)
      File "C:\Python\Python342x64\lib\urllib\request.py", line 455, in open
        response = self._open(req, data)
      File "C:\Python\Python342x64\lib\urllib\request.py", line 473, in _open
        '_open', req)
      File "C:\Python\Python342x64\lib\urllib\request.py", line 433, in _call_chain
        result = func(*args)
      File "C:\Python\Python342x64\lib\urllib\request.py", line 1202, in http_open
        return self.do_open(http.client.HTTPConnection, req)
      File "C:\Python\Python342x64\lib\urllib\request.py", line 1177, in do_open
        r = h.getresponse()
      File "C:\Python\Python342x64\lib\http\client.py", line 1172, in getresponse
        response.begin()
      File "C:\Python\Python342x64\lib\http\client.py", line 351, in begin
        version, status, reason = self._read_status()
      File "C:\Python\Python342x64\lib\http\client.py", line 313, in _read_status
        line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
      File "C:\Python\Python342x64\lib\socket.py", line 371, in readinto
        return self._sock.recv_into(b)
    ConnectionResetError: [WinError 10054]
    

Code of my program:

    
    
    import os, sys
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    from selenium.common.exceptions import NoSuchElementException
    from random import randint
    from time import sleep
    
    browser = webdriver.PhantomJS('C:\Program Files (x86)\PhantomJS\phantomjs.exe')
    
    browser.get('https://mobile.twitter.com/')
    sleep(randint(5,10))
    browser.save_screenshot('out1.png')
    g = open('C:\\Python\\Python342x64\\prog\\page.htm', 'a', encoding='utf8', errors='replace')
    g.write(browser.page_source + '\n')
    

If I use Firefox instead of PhantomJS, everything work fine. (or if i load
desktop version of twitter) How I can fix this problem with PhantomJS?


Answer: try to set user agent like: Android / Firefox 29: Mozilla/5.0 (Android;
Mobile; rv:29.0) Gecko/29.0 Firefox/29.0

