16

I'm using Selenium Webdriver in Python.

While running the script in headless browser(phantomjs) I'm getting an URLError:

<urlopen error [Errno 111] Connection refused> 

Any one can please help to handle this?

Mark Rowlands
  • 5,357
  • 2
  • 29
  • 41
user3172334
  • 161
  • 1
  • 4

1 Answers1

9

Having Googled this, it seems to happen unpredictably but after I've made a few requests with Selenium / Phantom. If I create a new webdriver with driver = webdriver.PhantomJS() then I'm able to continue making requests. I suggest others use the same workaround.

hcarver
  • 7,126
  • 4
  • 41
  • 67
  • 1
    What if starting a new driver isn't possible? Let's say you're scrolling down a Facebook news feed and you can't lose your scroll progress? – User Dec 02 '16 at 04:37
  • Yeah, it's a real pain. I didn't find any workarounds except to catch the exception and try again resetting the driver (as described above). The only other thing to try would be updating all your dependencies to the latest version. Without seeing the code you're running it's very difficult to suggest anything else. – hcarver Dec 02 '16 at 09:48
  • The code is here: http://stackoverflow.com/questions/40799703/httplib-badstatusline-on-linux-but-not-mac – User Dec 02 '16 at 17:29
  • 2
    Mind-boiling. If I assign the webdriver variable {wd = webdriver.Remote(srvc.service_url, capabilities)} in the global space, it's okay, if I put it in a function, return it and pass on to other functions, I get this error. First I thought, somehow I'd lost the content of the passed wd but no: printing it show that it points to the same object everywhere. It's anything but deterministic. – Gombai Sándor Oct 29 '17 at 14:07
  • 1
    asked 4 years ago and still a problem...what a pity – elchueko Jun 22 '18 at 13:51