title: How to assign to workers a proxy that requires user name - password and a custom user agent?
body: <p>How to assign to workers a proxy that requires user name - password and a custom user agent using Selenium, PhantomJS driver with Python bindings.</p>
  
  <p>I've had good success with creating many workers traversing my test website.  I can also assign a user agent or a proxy that does not require authorization.  But I haven’t figured out how to do both to the same worker at the same time yet.  </p>
  
  <p>However the real issue at the moment is assigning a proxy to the workers that require authorization by a user name and password.</p>
  
  <p>The Players:
  Selenium 2.33.0  / PhantomJS 1.9.1  / Python 2.7.3 / Ubuntu 12.04</p>
  
  <p>Me:
  Nube.  Python weeks, Linux days, Selenium hours, PhantomJS -= , SO first post</p>
  
  <p>Searches Yielded: 
  <a href="https://stackoverflow.com/questions/14699718/how-do-i-set-a-proxy-for-phantomjs-ghostdriver-in-python-webdriver">How do I set a proxy for phantomjs/ghostdriver in python webdriver?</a></p>
  
  <p>The answers may in fact be there and many other places I have read and re-read, but I can’t connect the dots at my present level.</p>
  
  <p>User Agent solved with this method.</p>
  
  <pre><code>dcap = dict(DesiredCapabilities.PHANTOMJS)           
  dcap["phantomjs.page.settings.userAgent"] = (
                  "Any User Agent string here”)
  driver = webdriver.PhantomJS(desired_capabilities=dcap)
  </code></pre>
  
  <p>Proxy <strong>without</strong> authorization works with this:</p>
  
  <pre><code>service_args = [
      '--proxy=127.0.0.1:9999',
      '--proxy-type=http,
      ]
  driver = webdriver.PhantomJS('/usr/local/bin/phantomjs,service_args=service_args)
  </code></pre>
  
  <p>If both above methods are used I’m unsure how to pass both proxy and UA to the PhantomJS driver.  ATM I’m only able to do one or the other and not at all with a proxy that requires authorization.</p>
  
  <p>Goal for this SO thread:  </p>
  
  <ol>
  <li>Learn how to assign a proxy that requires user name / password </li>
  <li>Assign a custom user agent to the same worker.</li>
  </ol>
  
  <p>Using Selenium, PhantomJS driver with Python bindings.</p>
  
  <p>The end game goal is to assign each worker a unique ip and pull from a pool of user agents.  Creating the logic for this I remain optimistic but the proxy with authorization is kicking me at the moment.</p>
  
  <p>As you can tell I’m very new to all of this and would appreciate any help and examples to this particular problem.  </p>
  
  <p>Thanks!</p>
  
  <p>EDIT:  Below accepted answer is incorrect.  Unable to reproduce below solution.  Only the proxy with authorization is assigned to the driver.  Still unable to assign both proxy and a user agent to the same driver.</p>
  
  <p>Any help or direction would be greatly appreciated.</p>
  
  <p>EDIT.02: Issue resolved. It was never a coding issue. A new proxy provider at the server level assigned a default UA that overrode the above script. Once this was removed all was good.</p>