SergeyPirogov / webdriver_manager

Apache License 2.0
2.05k stars 456 forks source link

__str__ returned non-string (type function) #60

Closed denny64 closed 5 years ago

denny64 commented 5 years ago

Getting this error on scrapinghub. Works okay locally. Any ideas?

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/scrapy/utils/defer.py", line 102, in iter_errback
    yield next(it)
  File "/usr/local/lib/python3.6/site-packages/sh_scrapy/middlewares.py", line 30, in process_spider_output
    for x in result:
  File "/usr/local/lib/python3.6/site-packages/scrapy/spidermiddlewares/offsite.py", line 29, in process_spider_output
    for x in result:
  File "/usr/local/lib/python3.6/site-packages/scrapy/spidermiddlewares/referer.py", line 22, in <genexpr>
    return (_set_referer(r) for r in result or ())
  File "/usr/local/lib/python3.6/site-packages/scrapy/spidermiddlewares/urllength.py", line 37, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "/usr/local/lib/python3.6/site-packages/scrapy/spidermiddlewares/depth.py", line 58, in <genexpr>
    return (r for r in result or () if _filter(r))
  File "/tmp/unpacked-eggs/__main__.egg/scraper/spiders/instagram.py", line 108, in parse
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
  File "/app/python/lib/python3.6/site-packages/webdriver_manager/firefox.py", line 18, in install
    return self._file_manager.download_driver(self.driver, path).path
  File "/app/python/lib/python3.6/site-packages/webdriver_manager/cache.py", line 70, in download_driver
    cached_binary = self.get_cached_binary(driver, path)
  File "/app/python/lib/python3.6/site-packages/webdriver_manager/cache.py", line 40, in get_cached_binary
    console("")
  File "/app/python/lib/python3.6/site-packages/webdriver_manager/utils.py", line 44, in console
    print(crayons.yellow(text, bold=bold))
TypeError: __str__ returned non-string (type function)
MarkBrook commented 5 years ago

Had the same issue when trying to run a couple of UI scenarios with locust. It's a problem of crayons library: __str__ method returned function instead of a string.

Maybe monkeypatching can help you. But, this is a reason for library to switch to some alternative like colorama, as crayons uses it under the hood.

SergeyPirogov commented 5 years ago

@denny64 @MarkBrook please provide some code examples! So I will be able to reproduce

MarkBrook commented 5 years ago

@SergeyPirogov alright, you can try this to reproduce.

Steps:

  1. Install locust first (pip3 install locust).

  2. Try to execute some simple scenario. Example:

    
    from selenium import webdriver
    from webdriver_manager.chrome import ChromeDriverManager

from locust import TaskSet, task, Locust

class UserBehaviour(TaskSet):

@task
def open_home_page(self):
    driver_manager = ChromeDriverManager()
    driver = webdriver.Chrome(
        # works when you hard-code a path (e.g. /home/user/.wdm/chromedriver/75.0.3770.90/linux64/chromedriver)
        executable_path=driver_manager.install()  
    )
    driver.get('https://github.com')

class User(Locust):

min_wait = 1000
max_wait = 10000
task_set = UserBehaviour


3. Run `locust -f my_locustfile.py`
4. Set 5 users to simulate and 1 hatch rate on `http://localhost:8089/`
5. Check console output